Results 1 to 12 of 12
  1. #1
    b0rt is offline Member
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default "Could not find the main class" when omitting "-jar"

    Hi there,

    I have sent an application to some friends for testing and all of them are getting the message "Could not find the main class" when trying to run the .jar file right after installing latest JRE.

    After some research I discovered that java by default registered the .jar extension to be run by "javaw.exe appName.jar", but if they run "javaw.exe -jar appName.jar" the app works like a charm.

    Is this normal?
    If .jar files are meant to be run with "javaw -jar" why the JRE installation doesn't add the "-jar" flag by default?

    If they should run both ways then my guess is there's an issue with my MANIFEST file:
    Java Code:
    Manifest-Version: 1.0
    Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
    Class-Path: lib/h2-1.3.158.jar
    Main-Class: minemizer.Main
    Inside the JAR you can find these two folders:
    minemizer (the one containing Main.class)
    META-INF (the one containing MANIFEST.MF)

    The code of this Main class is as simple as:
    Java Code:
    package minemizer;
    
    public class Main {
    
        public static void main(String[] args) {
            MainFrame mf = new MainFrame();
            mf.setVisible(true);
        }
    }
    Can someone identify the error here?

    Many thanks in advance!!

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

    Default

    java by default registered the .jar extension to be run by "javaw.exe appName.jar",
    That's strange. You need the -jar option for the java program to read the jar and look for the Main-Class entry in the manifest file.

    What OSs were these jar files being used on?
    I've manually configured my registry so a java install won't change my jar file commandlines so I don't know how java is currently setting the registry. It used to wipe out everything and require me to reset it all.

  3. #3
    b0rt is offline Member
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default

    Ok, so it's meant to be run with the -jar option. Then why doesn't the JRE installation add this command line argument by default?

    The testers are using Windows 7, could this be the problem?

    Thanks Norm!!

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

    Default

    the JRE installation add this command line argument by default?
    It should. I don't have Windows 7 so I have no idea what that could be doing to make a problem.
    The only way I've seen that kind of problem on XP is when I try to open a file that the OS doesn't know about and it asks me what command to use to open it. This, of course, doesn't create a commandline with any options.
    Hopefully some one that has recently installed java on Windows 7 will come along.

  5. #5
    b0rt is offline Member
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default

    Well your answer was a relief anyway. I have been mad reviewing the manifest file and compiling again and again trying to make it run without the "-jar".
    Now knowing it's mandatory so the problem isn't in my files I'm more relaxed somehow. But I should have used another thread title...

    Thanks a lot Norm!

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

    Default

    Its strange that it happened on more than one computer.

  7. #7
    b0rt is offline Member
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default

    Hi again Norm,

    Two more people tested it after installing JRE and one of them got this error message again, it's so weird...

    You said you configured your registry so any other installation wouldn't ruin your .jar association, could this be done through a .reg file or something automatized?
    I'm creating an installer including JRE and it would be nice to create this "unremovable" association assuring the program will always run fine on the machine.

    Thanks again, best regards.

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

    Default

    I've set the file extension associations manually using regedit. After having to reload my commandlines for jar files after every java installation, I changed the jafile entry to be named: jarfile_Norm. I then set the .jar entry to point to jarfile_Norm. After the install, I changed it back and manually merged in the new commandline. I have several versions of java.
    I guess you could save your current jarfile entry and merge it back in after the install.

    I have no idea how the JRE install can not associate .jar with the commandline with the -jar option.

  9. #9
    b0rt is offline Member
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default

    How should I save this entry to merge it automatically within the installer?
    Do you mean saving it in a .reg file and running it after the JRE install?

    Thanks Norm!

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

    Default

    It should not be necessary to change the registry after a JRE installation.
    There has to be another explanation.
    Unless the new install process has a bug. The old installation process certainly added an entry with the -jar option.

    What could the user doing the install of the JRE have done to screwed it up?


    Go to the Oracle site and ask on its forum to see if there are other explanations and a fix.

  11. #11
    b0rt is offline Member
    Join Date
    Aug 2011
    Posts
    22
    Rep Power
    0

    Default

    Ok Norm, I will do so.

    Thanks for all your help so far.

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

Similar Threads

  1. Receiving error "Could not find the main class"
    By Kalpesh in forum New To Java
    Replies: 2
    Last Post: 02-02-2011, 06:31 PM
  2. Error message "could not find the main class"
    By srwpchelp in forum New To Java
    Replies: 8
    Last Post: 12-23-2010, 09:15 PM
  3. Replies: 3
    Last Post: 08-25-2010, 10:21 AM
  4. Replies: 1
    Last Post: 06-30-2009, 02:32 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •