This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
hi, i wrote my first java program and compiled it using java 1.6.0. i made even a .jar file. Everything seems to be good but this .jar work only on my computer. when i run it on different computer there is problem with main class. Maybe it depends on version java. i tried to run that .jar on computer with java 1.5.09. you can try run it from java web start java web start It olso work only on my computer. I have JDK 1.6.0. thanks for any replies!
i ran that .jar on computer where is installed only standard java run time from http://java.com/en/ there wasn't set any classpath. when i tried run my jar from command line and there was an information: C:\pizzaria\classes\classes>java -jar app1.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
when i run .jar by double clic there is communicate: "Could not find the main class. Program will exit. " But everything is good on my computer where i wrote and compiled this program. So what is necessary to do on another computers to work my program correctly? my file .jar is available here thanks for any help
Joined: Aug 24, 2005
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
Your class file is in a format (Java version 1.6?) that is not supported by the JVM (Java version 1.5?) that you are attempting to run it with.
[ The following assumes you are compiling from the command line. If not you'll need to do the same things except within your IDE. ]
Run the command:
On the computer where you are compiling. And then run this command:
on the computer where you are running the class. They probably don't match. Compile the class again except this time add the -source parameter like this:
javac -source 1.5 MyClass.java
[ If you have any Java 6-specific stuff in your class the compilation will fail for obvious reasons. ]
Then try to run the resulting class on the other computer.
when i run .jar by double clic there is communicate: "Could not find the main class. Program will exit. "
To run the jar by double clicking on it you need to specify the class with the main method in the manifest (the file META-INF/MANIFEST.MF in the jar). The manifest should look something like this:
Manifest-Version: 1.0 Main-Class: MyClass [ November 01, 2006: Message edited by: Scott Johnson ]