How to run .jar file on unix?

I created a .jar file in windows.
I have to execute this .jar file on unix.

I run this command ( java -jar myJar.jar ), but it gives

  java.lang.UnsupportedVersionError 

I am using java version 1.5.0.12 on Unix.

+4
source share
7 answers
  java.lang.UnsupportedVersionError 

You must run jar compiled with JDK6 with local java1.5.

You can:

  • upgrade your jvm on Unix to version 1.6
  • or recompile your classes with

:

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

to check if you can generate compatible bytecode 1.5.

+5
source

The same as in Windows.

 java -jar file.jar 
+21
source

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

If you control a jar file, can you target Java 1.5 at compile time?

+1
source
  • Make sure the JDK or JRE is installed. Set if this is not the case.
  • set JAVA_HOME = # JDK / JRE home directory
  • $ JAVA_HOME / bin / java -jar file.jar

You should also remember that the JVM does not support transitions, so if you created a jar file using JDK 1.6, it will not work with JDK 1.5!

In this case, you can:

  • install JDK 1.6 on Unix

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

0
source

UnsupportedVersionError means that you compiled the Java source code with a newer version of Java than the one you are trying to run it with. Java is compatible with the lower version (newer versions of Java can run Java programs compiled with older versions), but are not compatible with the previous version (older versions of Java cannot run Java programs compiled with newer versions).

You say you use Java 5 on Unix. Did you compile it using Java 6 on Windows? Then it obviously won't work.

Possible solutions:

  • Compile the source code using Java 5 on Windows (the safest option)
  • Use compiler flags: -source 1.5 -target 1.5 at compile time (this will not protect you from using Java 6 classes from the standard library only, so this is not a complete guarantee that your program will work without errors in Java 5)
  • Migrating to Java 6 on Unix
0
source

Compile the application with Java 5 on a computer running Windows.

(By default, Java 6 uses Java 6 compatible code by default to take advantage of the new features. The easiest thing for you is to install the Java 5 JDK and use it to recompile your application)

0
source

I ran into the same problem. This is because the runtime and compile time versions of the JDK are different. Make a jar via eclipse after changing the version of the java compiler. The following link helped me.

http://crunchify.com/exception-in-thread-main-java-lang-unsupportedclassversionerror-comcrunchifymain-unsupported-major-minor-version-51-0/

0
source

All Articles