Results 1 to 8 of 8
  1. #1
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default 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 location
    Java Code:
    C:\Java Tools\com\dorksanddorkettes\dice\dice.class
    and so I have a manifest file called "manifest.txt." containing the single line;
    Java Code:
    Main-Class: com.dorksanddorkettes.dice.dice
    followed by a return.

    I compile the class (after using cd C:\Java Tools\)using the regular
    Java Code:
    jar cfm dice.jar
    then 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 containing
    Java Code:
    Could not find the main class: com.dorksanddorkettes.dice.dice. Program will exit.
    and when I try and run it through the control panel with
    Java Code:
    java -jar dice.jar
    I get a
    Java Code:
    NoClassDefFoundError: com\dorksanddorkettes\dice\dice (wrong name: dice)
    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.

    ~Karenthian~

  2. #2
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Have your manifest as:
    Java Code:
    Main-Class: dice

  3. #3
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    Nope, gave it a go and everything happens exactly the same except it changed from the whole address to just 'dice' now.
    ~Karenthian~

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    Your class should include the directories com/etc etc.
    You seem to be simply including the class file by itself...not that package structure.

  6. #6
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    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~

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    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.

  8. #8
    Karenthian is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Default

    AHA! That was what I'd missed out, adding the 'package' code to the dice.class! Thank you for that, I'll remember that in the future!
    Cheers,
    ~Karenthian~

Similar Threads

  1. Could Not Find Main Class (AGAIN!)
    By illjavathat in forum New To Java
    Replies: 54
    Last Post: 10-22-2010, 03:22 AM
  2. couldn't find main class
    By demonoid in forum New To Java
    Replies: 6
    Last Post: 10-10-2010, 02:44 AM
  3. could not find main class?
    By deathnote202 in forum New To Java
    Replies: 6
    Last Post: 05-10-2010, 08:57 PM
  4. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 04:07 PM
  5. JVM Could not find main class
    By banduskank in forum Advanced Java
    Replies: 2
    Last Post: 06-24-2008, 08:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •