2

I run a jar file on an external server. the jar-file is compiled by mvn on my local machine. the external server has java 1.7 installed, so I needed to explicitly tell maven to compile to java 1.7 because on my local machine I already use java 1.8.

However, I still get the following error when running the jar:

Exception in thread "main" java.lang.UnsupportedClassVersionError: io/package/name/Launcher : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:643)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: io.package.name.Launcher. Program will exit.

According to other threads Unsupported major.minor version 51.0 means that java 7 is expected (update: this is wrong. actually the error means that the system where I try to execute the jar can not handle the provided version which is 51 which equals java 7 / 1.7. so this implies that the system runs an even lower version (java 1.6?)). However, I double checked the compiled classes and they indeed should be compatible to java 7. but maybe I did something wrong when checking. I checked by using a HexEditor as explained here: how to check the jdk version used to compile a .class file

Here is a screenshot showing the 7th and 8th byte of Launcher.class. The 0x33 is 51. And 51 means that the class file is compatible with Java 7 (according to https://stackoverflow.com/a/1096159/973158).

A java -version on the server yields:

java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.1.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

And this is how I tell maven to compile to java 1.7 in pom.xml

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

What am I doing wrong? Could it be that there is some sort of cache on the server which still holds an old version of the class which was compiled to java 1.8?

FINAL UPDATE:

my code actually was java 1.7 compatible, however, I wasn't aware of the fact that java 1.6 was required. my bad.

Community
  • 1
  • 1
beta
  • 5,324
  • 15
  • 57
  • 99
  • 1
    How exactly are you running the jar file on the server? It seems to me more likely that somehow you're running Java 6 on the server - that's what the error message suggests. (If the problem was that it was compiling to Java 8, you'd get an error message about version 52.) – Jon Skeet Jul 16 '15 at 14:41
  • the server is actually a cluster which runs [slurm](http://slurm.schedmd.com/). there I need to create so called job-files which are similar to bash scripts. my job-file looks like this: http://i.imgur.com/Er9mbTA.png – beta Jul 16 '15 at 14:52
  • 2
    I suggest you run `java -version` *in the job file*... I suspect you'll find that it doesn't use the same version of Java that you're seeing from the shell when logging in directly. – Jon Skeet Jul 16 '15 at 14:54
  • that would be mean. okay, so now I did `java -version` in the job-file. will see what it will come up with. i have to wait some time, because the job is in the queue now.. will report back. – beta Jul 16 '15 at 14:57
  • A fine opportunity to upgrade the cluster to java 1.7. – Joop Eggen Jul 16 '15 at 15:31
  • :D it's the vienna scientific cluster... i think they won't agree. anyway, it's strange that in the main shell `java -version` yields 1.7, and that the actual java-version which is used when I execute a job is different. but please note that this is not confirmed, yet... my job is still in the queue, so i am still waiting. – beta Jul 16 '15 at 15:33
  • update: `java -version` from inside the job file yields `java version "1.6.0_34"`. so you guys were right. have to port my code now. – beta Jul 20 '15 at 13:43

0 Answers0