Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default Cannot find main class Windows.

    So I have coded my program on a mac. Its working fine on macs but when I send the jar to anyone with windows, they get Cannot find main class. The main class is in the jar. I know it is. I have no idea what is going on.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    To execute the contents of an Executable jar file, the jar file must contain a manifest file that has a Main-Class: record in it that refers to the class with then main() method. It should work the same on a mac as on windows.
    Is there something else about what the program does that could work on a mac and not on windows?
    Otherwise upload the jar file so someone on windows can look at it.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    I didn't put any manifest file into the jar but Im assuming NetBeans put it there...

    I found a manifest file in my project folder and it said this.


    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build

    The Jar runs on my mac and all other macs I sent it to.

    The error that it gets on windows is Could not find the main class: mail.bomb.Mbomb

    The class Mbomb, does exist inside the package mail.bomb and that is the main class. I set it as the main class in NetBeans

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    If it starts execution on a mac it should start execution on a pc that uses the command line:
    java -jar <JARFILENAME>.jar
    What does the manifest file in the jar file contain?

  6. #6
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    The manifest in the jar says

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.2
    Created-By: 1.6.0_26-b03-383-11A511 (Apple Inc.)
    Class-Path: lib/javaee.jar lib/mail.jar lib/swing-layout-1.0.4.jar
    X-COMMENT: Main-Class will be added automatically by build
    Main-Class: mail.bomb.Mbomb

    And yes, I did include the Lib folder with all the class paths in the zip with the jar.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Class-Path: lib/javaee.jar lib/mail.jar lib/swing-layout-1.0.4.jar
    Are these jar files in the correct folder on the PC, like they are on the mac?

    What versions of the JRE are involved?

  8. #8
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    You mean are the jars in the lib folder? Well... i don't think windows would change around the structure of my zip... But just to let you know, the lib folder is not inside the jar. Its just in the archive. As far as I know, I am running the latest version of JRE because Java is built into Mac OSX and it checks for updates daily.
    I don't know that the windows users were using. If you want to take a look at it for yourself, Cjs Program.zip there it is

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    You mean are the jars in the lib folder? Well... i don't think windows would change around the structure of my zip...
    What does the zip file have to do with this? I assumed all the files were in folders on the PC. If some are in a zip, I don't think the java command will look in the zip file.

  10. #10
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    I don't think you are understanding me correctly. I put all the files in a zip, the jar and the lib folder. Then, the user extracts the files from the zip and runs the jar.

  11. #11
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Download the zip and you will see what I mean.

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    The only problem I had was the space in the middle of the jar file filename

  13. #13
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Ok so it worked? Its just the space in the filename?

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    It was a problem for me. I executed it from batch file with a security manager. I needed to remove the space for it to work.
    I normally don't put spaces in filenames as they often cause problems on windows.

  15. #15
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Ok, I removed the spaces and my friend still gets the same error. Is there a way to fix it without executing it from a batch file with a security manager?

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Sorry, I don't run other people's code outside of a security manager.

    But, It did work in that restricted mode.

    On the PC, open a command prompt window, change to a directory with the jar file and lib folder and enter:
    java -jar MailBomb.jar

    Copy and paste here what shows on the console screen.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  17. #17
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Ok, I tested it on my pc running vista and it worked fine. The Jar opened fine without even deleting the space in the name but the GUI was weird, one of the text boxes was out of place and the Jframe background color was wrong and the fonts were wrong. It seems to run differently on every computer. On my sisters mac, same os and Java version, the gui was fine except the fonts were wrong. On my friends mac, older version of mac osx, not much older, it worked fine, exactly as it did on mine. When I did the command you told me on my pc, nothing happened, it just opened the program. I don't understand :(

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    When I did the command you told me on my pc, nothing happened
    Does that mean the program worked as you expected?

  19. #19
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Yes, other than the guy was a little weird

  20. #20
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. Could not find main class
    By yetty4ever in forum New To Java
    Replies: 7
    Last Post: 02-16-2011, 07:38 PM
  2. Could Not Find Main Class (again)
    By illjavathat in forum New To Java
    Replies: 25
    Last Post: 11-23-2010, 09:49 AM
  3. Could Not Find Main Class (AGAIN!)
    By illjavathat in forum New To Java
    Replies: 54
    Last Post: 10-22-2010, 03:22 AM
  4. could not find main class?
    By deathnote202 in forum New To Java
    Replies: 6
    Last Post: 05-10-2010, 08:57 PM
  5. 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

Posting Permissions

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