tags:

views:

1424

answers:

6

I have generated .jar file in windows.
I have to execute that .jar file in unix .

I am running that command (java -jar myJar.jar), but it's giving

 java.lang.UnsupportedVersionError

I am using java version 1.5.0.12 in Unix.

+11  A: 

Same as under Windows.

java -jar file.jar
Bombe
A: 
  • Check that JDK or JRE is installed. Install if it is not.
  • set JAVA_HOME= # JDK/JRE home directory
  • $JAVA_HOME/bin/java -jar file.jar

You should also keep in mind that JVM are not forward compatible, so if you've made a jar-file using JDK 1.6, it won't work with JDK 1.5!

In this case you may either:

  • install JDK 1.6 to Unix

  • recompile the jar with -target 1.5 flag (but you may get any sort of errors due to API incompatibilities, so the first way is much better)

Vanya
you forget `-source and -bootclasspath` parameters (see my answer below)
VonC
+1  A: 

Have you tried using a newer version of Java on your Unix system?

If you control the jar file, could you target Java 1.5 when it's compiled?

izb
+4  A: 
 java.lang.UnsupportedVersionError

You must be trying to launch a jar compiled with JDK6, with a local java1.5.

You can either:

  • upgrade your jvm on Unix to 1.6
  • or re-compile your classes with a

:

  javac -source 1.5 -target 1.5 -bootclasspath /path/to/jre1.5/lib/rt.jar

to check if you can generate 1.5 bytecode compatible.

VonC
A: 

UnsupportedVersionError means that you have compiled the Java source code with a newer version of Java than what you're trying to run it with. Java is downwards compatible (newer versions of Java can run Java programs compiled with older versions), but not upwards compatible (older versions of Java cannot run Java programs compiled with newer versions).

You say you're using Java 5 on Unix. Did you compile it using Java 6 on Windows? Then it's obviously not going to work.

Possible solutions:

  • Compile your source code using Java 5 on Windows (the safest option)
  • Use the compiler flags: -source 1.5 -target 1.5 while you compile (this will not protect you against using Java 6-only classes from the standard library, so this is not a full guarantee that your program will run without errors on Java 5)
  • Upgrade to Java 6 on Unix
Jesper
You forgot `-bootclasspath` (I just added the option in my answer;) )
VonC
A: 

Recompile your application with Java 5 on your Windows machine.

(Java 6 generates Java 6 compatible byte code by default to use new facilities. The easiest for you is to install a Java 5 JDK and use it to recompile your application)

Thorbjørn Ravn Andersen