wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes run jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "run jar " Watch "run jar " New topic
Author

run jar

Oczek Oczkowy
Greenhorn

Joined: Nov 01, 2006
Posts: 12
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!


fak de sys
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
What is the error message you have the problem with the main class?

Is the jar properly specified in your classpath?
Oczek Oczkowy
Greenhorn

Joined: Nov 01, 2006
Posts: 12
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
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
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:

javac -version

On the computer where you are compiling. And then run this command:

java -version

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: run jar
 
Similar Threads
Using the sun.jvmstat.* api
Applet security - is signing all you need?
Java Web Start and compiling servlet
Module Rampart in Tomcat ClassNotFoundException
BeeServlet and MVC2... again