Results 1 to 20 of 20
  1. #1
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Netbeans created .jar file says missing main method...

    I have a project that I made in netbeans and after setting as my main project I did a clean build. I win.rar-ed the created .jar file and the library file in the dist folder. The jar file runs fine on MY PC. However, when I copy the .rar file on to my flashdrive and try to run the .jar file on any other computer it gives me a missing main method error.

    The manifest.mf file only contains the following: Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build


    This is my first attempt at packing a program as a .jar file so I'm not sure what I'm missing.

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

    Default Re: Netbeans created .jar file says missing main method...

    when I copy the .rar file on to my flashdrive and try to run the .jar file on any other computer
    I'm not familiar with a .rar file. I've created and used lots of jar files.
    You say you copy a .rar file and "then try to run the .jar file"
    What jar file are you talking about? Did you copy the jar file also to the PC also?
    How do you execute the jar file?
    Does the jar file contain a manifest file with a Main-Class: record?

  3. #3
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    I have the same issue when I zip the file as well.
    NetBeans creates a jar file called SphereCCGClient.jar in my dist folder. I zip that jar along with the lib folder that is also in the dist folder. I copy the zip to my flash drive then on another PC I extract the files and attempt to run SphereCCGClient.jar. It tells me missing main class com.sphereccgclient.Login.

    There is a manifest.mf file located above the dist directory. It contains the lines: Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build

    Are there more files that I need to be including? I was under the impression that the jar file along with the lib folder were sufficient.
    Thanks!

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

    Default Re: Netbeans created .jar file says missing main method...

    If the manifest file in the jar file does not contain a Main-Class: record then the java program will not know which class has the main method that it is supposed to execute.
    What is the classname with the main() method?

    missing main class com.sphereccgclient.Login.
    This message text looks like java is finding a Main-Class: record that refers to the com.sphereccgclient.Login class but can not find that class.

    This is confusing because you said there was NOT a Main-Class: record in the manifest file.
    It there was not, then where did java get the class name in the error message?

  5. #5
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    All the manifest file says about the main class is: "Main-Class will be added automatically by build"
    When I view the project.properties file in the nbproject folder I find the lines:
    main.class=com.sphereccgclient.Login
    manifest.file=manifest.mf

    If I take the created sphereccgclient.jar file and extract the contents, I can manually locate the com.sphereccgclient.Login.class file, so I don't understand why the jar cannot locate it when I try to execute it.

    Should I try to create the jar with something outside of netbeans?

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

    Default Re: Netbeans created .jar file says missing main method...

    Are you looking at the manifest file that is contained in the jar file?
    That is the one I'm talking about and the one used by the java command.

    You can use a zip utility program to look in the jar file and view its contents.

  7. #7
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    Ok I extracted the jar file's contents and found a Manifest.mf file that was in the META-INF file that was extracted from the jar.

    It's contents were:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 16.3-b01 (Sun Microsystems Inc.)
    Class-Path: lib/ant-contrib-1.0b3.jar lib/org.eclipse.persistence.antl
    r.jar lib/org.eclipse.persistence.asm.jar lib/org.eclipse.persistence
    .core.jar lib/org.eclipse.persistence.jpa.jar lib/org.eclipse.persist
    ence.jpa.modelgen.jar lib/org.eclipse.persistence.oracle.jar lib/java
    x.persistence.jar lib/grizzly-comet.jar lib/jsf-api.jar lib/jaxb-api-
    osgi.jar lib/bean-validator.jar lib/javax.enterprise.deploy.jar lib/j
    avax.ejb.jar lib/javax.transaction.jar lib/jstl-impl.jar lib/jsf-impl
    .jar lib/javax.management.j2ee.jar lib/javax.jms.jar lib/javax.annota
    tion.jar lib/jersey-core.jar lib/javax.security.jacc.jar lib/javax.re
    source.jar lib/javax.mail.jar lib/weld-osgi-bundle.jar lib/jaxb-osgi.
    jar lib/javax.servlet.jsp.jar lib/webservices-osgi.jar lib/javax.serv
    let.jsp.jstl.jar lib/jaxm-api.jar lib/javax.security.auth.message.jar
    lib/webservices-api-osgi.jar lib/javax.servlet.jar lib/web-core.jar
    lib/jackson-core-asl.jar lib/jackson-jaxrs.jar lib/jackson-mapper-asl
    .jar lib/jersey-client.jar lib/jersey-gf-server.jar lib/jersey-json.j
    ar lib/jersey-multipart.jar lib/jettison.jar lib/mimepull.jar lib/gf-
    client.jar lib/derby.jar lib/derbyclient.jar
    Main-Class: com.sphereccgclient.Login


    edit: I want to reiterate that the jar file runs just fine on the computer on which the program was created. No matter where on the harddisk I put the jar file, I can double click it and the program opens. But it gives the main class not found error on my other computers. My other computers say that java is installed and is up-to-date (supposing this is all they need to run the jar).

    I very much appreciate the help you're giving. It is very important that I figure this out, I have spent months creating the program.
    Last edited by ChexWithRaisins; 11-22-2011 at 11:49 PM.

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

    Default Re: Netbeans created .jar file says missing main method...

    The manifest file has a HUGH Class-path: list of jar files. Are all those jar files present when you try to execute the program?
    The Main-Class: record is there. Have you checked that the com.sphereccgclient.Login class is there?
    Is the Login.class file in the com/sphereccgclient folders.

    Can you try this and copy the contents of the command prompt window and post it here.
    The dir command will show what is in the folder.
    Open a command prompt window, change to the folder with the jar file and enter the following commands:
    dir
    java -jar SphereCCGClient.jar

    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.

  9. #9
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    I think I'm doing something wrong. I change directory to the jar folder then typed: dir and hit enter.
    I then typed: java -jar SphereCCGClient.jar and hit enter (doing this just made the program run, and did not produce any output in the cmd window)

    Here is a copy of the cmd window after executing those two commands:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Chex>cd my documents\netbeansprojects\sphereccgclient\
    dist

    C:\Documents and Settings\Chex\My Documents\NetBeansProjects\SphereCCGClient\dis
    t>dir
    Volume in drive C has no label.
    Volume Serial Number is 40CE-E7FB

    Directory of C:\Documents and Settings\Chex\My Documents\NetBeansProjects\Spher
    eCCGClient\dist

    11/22/2011 06:22 PM <DIR> .
    11/22/2011 06:22 PM <DIR> ..
    11/22/2011 06:22 PM <DIR> lib
    11/22/2011 06:22 PM 1,331 README.TXT
    11/22/2011 06:22 PM 5,647,025 SphereCCGClient.jar
    2 File(s) 5,648,356 bytes
    3 Dir(s) 349,181,407,232 bytes free

    C:\Documents and Settings\Chex\My Documents\NetBeansProjects\SphereCCGClient\dis
    t>java -jar SphereCCGClient.jar

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

    Default Re: Netbeans created .jar file says missing main method...

    If the program runs OK the java program does not print any messages in the command prompt console window. If your program executed any println statements their output would show on the console.

    If the program ran successfully when you manually entered the java command, then I think the problem is with the way the OS is configured to execute the java command with your jar file.

  11. #11
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    Ok so it looks like it has something to do with how my other computers are set up. Is there a command line prompt that I can run in the windows console to see if the JVM is set up correctly on a computer?

    edit: I just executed the command: java -jar SphereCCGClient.jar
    on my other computer and the program ran correctly. But it still won't let me run by double-clicking the file.
    Last edited by ChexWithRaisins; 11-23-2011 at 01:02 AM.

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

    Default Re: Netbeans created .jar file says missing main method...

    What I don't understand is how the error message contains the class name from the jar file's manifest file.
    That would mean that the java program is reading it OK.

  13. #13
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    It doesn't make sense to me either. And like I said, I can extract the SphereCCGClient.jar file contents and manually find the main class in the com sub-directory.

  14. #14
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    I am getting a subsequent issue that I feel is related to my other problem. I still can not execute the jar file with a double-click, however I can run it with java -jar SphereCCGClient.jar

    HOWEVER, when the program attempts to utilize the image resources (jpg) that are bundled with the jar file, I am getting a null pointer exception. Just as before, I can extract the files from the jar and manually locate the image files.

  15. #15
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    Addendum to my previous post:

    The program is selectively displaying jpg resource files. Each of the jpgs is displayed as an icon in a JLabel. Any jpg that was set as the JLabel icon in the NetBeans form editor displays properly. However, any of the jpgs that are determined dynamically AFTER the program runs are causing a null pointer exception.

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

    Default Re: Netbeans created .jar file says missing main method...

    Any jpg that was set as the JLabel icon in the NetBeans form editor displays properly. However, any of the jpgs that are determined dynamically AFTER the program runs are causing a null pointer exception.
    What is the difference between the IDE generated code that works and the other code that does not work?

  17. #17
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    Here is an example of the IDE generated code that works:
    labelTransparent.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Symbols/transparentspherelabel.JPG"))); // NOI18N

    Here is an example of the dynamic code which does not work:
    backGround.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/backgroundtemplate1.jpg")));

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

    Default Re: Netbeans created .jar file says missing main method...

    They look the same.

  19. #19
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default Re: Netbeans created .jar file says missing main method...

    Just thought I'd let you know that I figured out what the issue was. Apparently when netbeans tries to find a resource file the file is not case-sensitive. But, the .jar file IS case-sensitive when it looks for resources. So it turns out my issue was that the code was trying to find "image.jpg" when it should have been "image.JPG"

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

    Default Re: Netbeans created .jar file says missing main method...

    Thanks for letting us know.
    I'd expect the classloader to be case sensitive.

Similar Threads

  1. Help with an input.Line issue in a method I've created
    By The_Steak in forum New To Java
    Replies: 3
    Last Post: 11-06-2011, 03:42 AM
  2. list created in netbeans
    By Ioannis Spanomichos in forum NetBeans
    Replies: 1
    Last Post: 10-27-2011, 03:34 PM
  3. Replies: 2
    Last Post: 09-27-2011, 03:59 PM
  4. main not passing information to created class
    By Teclis in forum New To Java
    Replies: 2
    Last Post: 04-19-2011, 08:58 PM
  5. Replies: 2
    Last Post: 03-09-2009, 02:36 AM

Posting Permissions

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