Java UnsupportedClassVersionError Issue - java

I understand the UnsupportedClassVersionError to be caused when I compile my java files in a newer version than the JVM the class file will be run on.
I'm working on a program that will run on an IBM i Series box, which is running Java 1.6. I've cross-compiled my files to use 1.5 for the source and target values. The actual command used is:
javac -source 1.5 -target 1.5 -bootclasspath C:/dev/languages/java/jdk1.5.0_22/jre/lib/rt.jar -extdirs "" -classpath "c:/dev/QIBM/ProdData/OS400/jt400/lib/*;/psmssys/java/src/com/gy/as400/common;." $(find ./com/gy/as400/bladder/install/* | grep .java)
Understand I am compiling the files on a Win 7 box running Java 1.8.0_131
Once the classes are compiled if I then run
javap -verbose
on any of the resulting classes, the Major Version shows 49which according to this wiki article should be compatible with JVM 1.5 and up.
I've tried to cross-compile to 1.4 but that would require me to rewite a significant portion of my code to not use FOR...EACH and generic lists.
What am I missing here.

Thank you #rdean400.
I got to thinking and went back through my transfer logs and found some errors had occurred moving the class from my dev box to the test box. I cleared out all the existing class files and transferred them again. This resolved the UnsupportedClassVersionError.

Related

How to change the used java version of SoapUI?

I have multiple Java versions installed. I switch versions when needed.
If I use Java 8 as default, SoapUI will use it. A Popup with with this error will show then :
java.lang.UnsupportedClassVersionError: com/eviware/soapui/SoapUI has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Since the 5.6.0, SoapUI need a Java version ⩾ 9. So I want to specify the java version used by SoapUI when my default version is java 8.
Notes :
By default I mean, the version printed when : java -version is executed on the Terminal.
In the file SoapUI-5.6.0/bin/SoapUI-5.6.0 :
Uncomment the var INSTALL4J_JAVA_HOME_OVERRIDE at the beginning of the file
Assign the java home (JRE OU JDK) to INSTALL4J_JAVA_HOME_OVERRIDE
Example :
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/lib/jvm/jre-11/
I leave here my solution since i lost 4 hours just to understand that if you have java 8 and you use Ubuntu, you can save the world but SoapUI 5.6.0 won't work.
So the solution is to download an older version, like 5.4.0
Don't bother looking for one if you're an Ubuntu lady/guy, just use this command:
$ wget https://s3.amazonaws.com/downloads.eviware/soapuios/5.4.0/SoapUI-5.4.0-linux-bin.tar.gz
Then unzip and untar the downloaded archive:
$ gunzip SoapUI-5.4.0-linux-bin.tar.gz
$ tar xvf SoapUI-5.4.0-linux-bin.tar
Finally start SoapUI by entering in the folder where it is installed and run:
/bin/soapui.sh
in case it helps anyone - I have java-11 alongside java-8 (with latter being the default) and SoapUI-5.6.0.
Solution: I've set the INSTALL4J_JAVA_HOME_OVERRIDE variable in SoapUI-5.6.0 to:
INSTALL4J_JAVA_HOME_OVERRIDE="/usr/lib/jvm/java-11-openjdk-amd64/"
Just use nano or gedit, etc. to modify (don't forget to use elevated permissions, if neccessary).
Best regards

Java: I cannot execute a compiled Java code

C:\Users\YusufGalip\Desktop\JavaDeneme>java deneme
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: deneme has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I got this error when i tried to run a compiled program.
It's probably compiled with a more recent version of java than the one you are attempting to use running the program. Do you have multiple versions of Java installed?
Try java -version and javac -version and compare the versions. If you use and IDE/editor where Java is configured in the settings, see that it points to the expected directory.
You've compiled your class with Java 11 (55) while you're still trying to execute/run them using Java-8(52).
Either compile the code using Java-8 or execute with Java-11.
The error clearly says that the compiler version was higher than the JVM version with which you are trying to run. That is why you are getting the error on running.
Java 8 uses major version 52
Java 11 uses major version 55
Reference:
https://en.wikipedia.org/wiki/Java_class_file#General_layout
=================
#DO THE FOLLOWING
change your path to point to a more recent version or if you are aware of the version using which the program was compiled, install the version and then execute the same command to run
1) run java -version now
2) Note down the version
3) complete the above #DO ****
4) execute 1) again
5) you should see a different or the latest version
6) run your program :) and you should be able to .... post your results
Finally I solved with your help.
There were 2 Java in my computer one of them is "Java SDK Tools 11" and the second one is "Java Runtime 8" I uninstalled the "Java Runtime 8" and it worked.Thank you for your help.

How do we decide which java version is used to compile a version of library in maven?

My local setup has all java 6 configured. I needed catalina jar file. So I took the latest one -
http://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina/8.0.15
but that gave me following errors/warnings
warning: javalangObject.class(javalang:Object.class): major version 51 is newer than 50, the highest major version supported by this compiler.
and build failed.
Only way this was possible is that catalina.jar is compiled with java 7 and my setup is using java6. I confirmed that was the case by using an older version of the library.
http://mvnrepository.com/artifact/org.apache.tomcat/catalina/6.0.35
I would like to know how do we know which library version is compiled with which version of java. Specifically in Maven I don't see any such information.
Major version of 51 means it was compiled with Java 7. Major version 52 means, it was compiled with Java 8. Java 6 has major version 50.
You may extract some class files out of the jar downloaded from Maven. Then check the major version of the class as below:
$ javap -verbose someclass.class | grep -i major
Which will indicate the javac version used for compiling.

How to force Java 8 wsimport command-line to generate 1.6 target compatible code

I'm trying to upgrade an existing build system to use Java 8 instead of a Java 5/6 compiler, however, I still have to generate outputs compatible with Java 5/6. Overall this is trivial (-target 1.6), but I am having difficulty doing so with code generated from wsimport (using the version in JDK 8 bin).
I'm using Java HotSpot 64-bit server VM (build 25.20-b23), JDK 1.8.0_20.
The wsimport command is being called from a command-line to generate code and the outputs packaged directly from there. For legacy reasons I am unable to change this process (such as to use ant), so I need to solve the problem from the command-line.
What I run is: "wsimport WSDL_FILE" (actual file doesn't matter)
then run "javap -verbose CLASS | grep major" on any of the classes in the output to check the version: it always comes out 52.
I've tried using -J argument to wsimport to pass options to the javac compiler, however none of the below have worked:
wsimport "-J-target 1.6" WSDL (fails with unrecognized option -target 1.6" coming from wsimport)
wsimport "-J-Djavac.target=1.6" WSDL (no effect)
wsimport "-J-Djavac.opt.target=1.6" WSDL (no effect)
Presumably there's either some variation on passing the target through that works or some property settings that should work; if it's one I'm using, then I haven't figured out how to pass it correctly.
Assuming that wsimport creates Java 6 compatible source code, no reason it shouldn't, but who knows, then the solution is to simply add -Xnocompile to wsimport, and then build the source directly yourself, using whatever mechanism is comfortable for your process.

Should the ejb jar be compiled on the same JVM that deploys the JBOSS AS?

I have two machines with difference JVM versions (1.6 and 1.5)
I have a JBOSS Server running on the one of JDK1.5. I've created a ejb jar file on the machine of JDK1.6.
When I get to deploy the EJB Jar into the JBOSS(4.3), I get the following error:
16:05:41,878 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=ejb1_test.jar
java.lang.ClassNotFoundException: Unexpected error during load of: org.daz.TimeServiceBean, msg=Bad version number in .class file
If you want to run in java 1.5 then you should compile in java 1.5 or lower.
Alternatively, if you simply must run JDK 6 then as #Paul Tomblin suggests you can use the -target javac option. One warning on this though, if you are using any of the new Java 1.6 API features javac 1.6 (e.g. setting File perms) javac will not complain but you will get errors when running this code in java 1.5.
javac has a -target option that allows you to compile to a 1.5 jvm with a 1.6 compiler. See javac -help for details.

Categories