2

I am having trouble trying to run a .jar application on Kubuntu. I created an application in NetBeans in Windows and compiled it into a .jar file. First Windows couldn't find the main class. I searched the internet and fixed some registry values for the JRE and everything works fine now. However, the same problem has arised in Kubuntu, but I can't find anything of help. I've even tried uncompressing the .jar file and modifing the class path in the manifest file with many different path addresses, but nothing works.

Since the problem in Windows was on the JRE and not on my application, I think the same is happening in Kubuntu. An important note is that I've installed NetBeans on Kubuntu too and when I debug or run the application under Netbeans, it works fine, but when I compile it and try to run it with:

java -jar "MBoxTest.jar"

I get the same errors I got on Windows including the final one that says it cannot find the main class:

Exception in thread "main" java.lang.UnsupportedClassVersionError: my/mboxtestui/MBoxTestUI : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: my.mboxtestui.MBoxTestUI. Program will exit.
Michael
  • 55
  • If you had to edit the windows JRE to make your program work, and it doesn't work on the JRE on kubuntu... it's something wrong with your application. The JRE's are used by many, many people without changing anything. Do remember that NetBeans does a lot of 'behind-the-scenes' support to help fragments and 'almost-working' applications to run for debug purposes. Have another look at your application. Sun's Tutorials can help – lornix Jul 13 '12 at 03:45

1 Answers1

4

You are running higher version code(51 =java7) against lower version JVM. Therefore, compile and run your code against the same version of jdk. I guess that you may have more than one version of java runtime installed.

  • Yes! You are right! I have JRE 6 and JRE 7, but the one running with the command line is JRE 6. Thank you very much. For anyone with the same problem, if you are using NetBeans: – Michael Jul 13 '12 at 03:56
  • Right click your project name and click "Properties". Go to "Source" and then change the "Source/Binary Format" to the version of your JRE. Examples: JDK 6 or JDK 7 – Michael Jul 13 '12 at 03:59