JAR Problems

Ok so I wrote a program. Compiled it. Exported it to a .jar. Tested it on my computer via double click, and java -jar prog.jar

command.

So it works, so I send it to friends and they can't get it to work. Getting the error "cannont find main class" or more specifically....

java -jar"ipod.jar"

Exception in thread"main" java.lang.UnsupportedClassVersionError: Bad version n

umber 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)

I don't understand why it wouldn't work so any help is definitely appreciated

[1355 byte] By [imdandmana] at [2007-11-27 7:29:28]
# 1
I believe this happens when you compile the code with one version of Java and run it with a different version of Java.
floundera at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...
# 2

> I believe this happens when you compile the code with

> one version of Java and run it with a different

> version of Java.

And more specifically when you compile with a newer version and run with an older version.

Try using the -target switch when you compile and choosing an older version (what your friends have).

See http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html#options

cotton.ma at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...
# 3

So that command would just generate my class files in an older version of java right?

How would I type the command. All my source and class files are in 1 directory and I'm on a windows xp machine.

Also, since this generates my class files, how do I get everything in a .jar file once it's done?

imdandmana at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...
# 4
javac -source "1.4" -target "1.4" *.java
gimbal2a at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...
# 5
Sorry... and how do i get those resulting class files in a .jar?
imdandmana at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...
# 6
jar cf myJar.jar *.class
DarumAa at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...
# 7

> javac -source "1.4" -target "1.4" *.java

That doesn't work. This one from the sun website doesn't work either. I did have to download the old JDK 1.4 but it still gives this error.

D:\stats>javac -source"1.4" -bootclasspath c:\j2sdk1.4.2_14\lib\ -extdirs "" gui

podstats.java

javac: invalid flag: -source1.4

Usage: javac <options> <source files>

use -help for a list of possible options

D:\stats>

and then I abandonded that Idea and went back and used the old 1.4 compiler explicitly and it gave me about 100 compiler errors!

This is rediculously frustrating. You think that when you "upgrade" java your new programs would be backwards compatable!!

imdandmana at 2007-7-12 19:09:37 > top of Java-index,Java Essentials,Java Programming...