Results 1 to 8 of 8
Thread: Could not find main class
- 03-30-2011, 02:26 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
Could not find main class
Hello there,
I'm learning Java and I'm not a complete idiot, but this is perplexing me.
I have a simple app that will basically roll a dice. It gets input about number of sides, times to roll and modifiers, calls the Random class and then prints all the individual rolls and lastly the total. Fairly simple, no?
I've compiled it and it all works perfectly through Command Prompt and so I figure I want to make it into a little stand alone jar.
Firstly I make it into a .jar. No problem, all works. Secondly I add a manifest file, and I fear this is the problem.
My dice.class is in the locationand so I have a manifest file called "manifest.txt." containing the single line;Java Code:C:\Java Tools\com\dorksanddorkettes\dice\dice.class
followed by a return.Java Code:Main-Class: com.dorksanddorkettes.dice.dice
I compile the class (after using cd C:\Java Tools\)using the regularthen the location of the manifest.txt and the location of the dice.class. It all works well and I end up with a nice little dice.jar. Now I've been told that from here you can double click and it will run, but it doesn't. I get a nice dialogue box containingJava Code:jar cfm dice.jar
and when I try and run it through the control panel withJava Code:Could not find the main class: com.dorksanddorkettes.dice.dice. Program will exit.
I get aJava Code:java -jar dice.jar
So fine minds of Java Forum... where am I going wrong? I've looked all over the place and can't see a reason this shouldn't be working. If there is a typo in the code here then assume I didn't make it when I tried all this.Java Code:NoClassDefFoundError: com\dorksanddorkettes\dice\dice (wrong name: dice)
~Karenthian~
- 03-30-2011, 02:29 AM #2
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
Have your manifest as:
Java Code:Main-Class: dice
- 03-30-2011, 12:36 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
Nope, gave it a go and everything happens exactly the same except it changed from the whole address to just 'dice' now.
~Karenthian~
- 03-30-2011, 12:42 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Have the manifest file be in the same file as the main class and do Main-Class: dice
Then do
Java Code:jar cvfm jarname manifest classes
- 03-30-2011, 01:08 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Your class should include the directories com/etc etc.
You seem to be simply including the class file by itself...not that package structure.
- 03-30-2011, 02:16 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
Sunde; that is exactly what I've done every time (though I must admit unless there is a problem converting it I skip the verbose output).
Tolls; I'm not sure I understand. My program only has one class (dice.class)... what do you mean the class should include directories?
~Karenthian~
- 03-30-2011, 02:23 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Does your java for the dice class start like this:
?Java Code:package com.dorksanddorkettes.dice;
If so, then you have a com.dorksanddorkettes.dice.dice class, which means your jar file should contain the com/dorksanddorkettes/dice directory structure as well, since that's part of your defined package structure.
If not, then sorry...I have misinterpreted your directory names.
- 03-30-2011, 03:02 PM #8
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Could Not Find Main Class (AGAIN!)
By illjavathat in forum New To JavaReplies: 54Last Post: 10-22-2010, 03:22 AM -
couldn't find main class
By demonoid in forum New To JavaReplies: 6Last Post: 10-10-2010, 02:44 AM -
could not find main class?
By deathnote202 in forum New To JavaReplies: 6Last Post: 05-10-2010, 08:57 PM -
Could not find main class - JDK 1.6
By Syranno in forum New To JavaReplies: 1Last Post: 07-25-2008, 04:07 PM -
JVM Could not find main class
By banduskank in forum Advanced JavaReplies: 2Last Post: 06-24-2008, 08:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks