2

I am deploying Spring application on Tomcat 8 server. The application uses Jena API from this maven repository. When I open the application in browser, it shows the following message (the same application can be opened without any problem when I do not use Jena API):

HTTP Status 500 - Handler processing failed; nested exception is java.lang.UnsupportedClassVersionError: org/apache/jena/query/QueryExecutionFactory : Unsupported major.minor version 52.0 (unable to load class org.apache.jena.query.QueryExecutionFactory)

I tried to solve this problem by changing the version of Java for Tomcat 8. I opened sudo nano /etc/init/tomcat.conf and changed JAVA_HOME:

env JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre

Then I restarted Tomcat 8 server and redeployed my application, but the same problem still exists. In fact I noticed that for some reason JRE 7 appears in the log message when starting the server:

May 07, 2016 5:26:11 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Java Home: /usr/lib/jvm/java-7-oracle/jre May 07, 2016 5:26:11 PM org.apache.catalina.startup.VersionLoggerListener log INFO: JVM Version: 1.7.0_80-b15 May 07, 2016 5:26:11 PM org.apache.catalina.startup.VersionLoggerListener log INFO: JVM Vendor: Oracle Corporation

I am not sure if this might be a possible reason of why the problem is not fixed. Any solution is highly appreciated.

P.S. I know that java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime. So, do I understand correctly that Jena API was compiled with lower JDK?

f_puras
  • 2,521
  • 4
  • 33
  • 38
Klue
  • 1,317
  • 5
  • 22
  • 43

1 Answers1

3

Actually as far as I can see in the jar that you provide, the major version of Jena is 52 which means that it has been compiled with java 8, I believe that your problem is more due to the fact that you run tomcat with java 7

For more details about how to know the version of a class, please refer to this answer

To indicate Tomcat which JDK to use, you need to set the JAVA_HOME to the path of a JDK not a JRE by doing this export JAVA_HOME=/usr/lib/jvm/java-8-oracle. More details here

Community
  • 1
  • 1
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
  • Do you know how to run Tomcat with java 8? As I explained in my answer I tried to change Tomcat's java from `/etc/init/tomcat.conf`, however it seams that there is another configuration that I had to change. – Klue May 07 '16 at 16:21
  • you need to set JAVA_HOME to the path of the jdk not the JRE, so try this env JAVA_HOME=/usr/lib/jvm/java-8-oracle – Nicolas Filotto May 07 '16 at 16:24
  • Ok, thanks. I will check it, recompile the project and let you know if it worked. – Klue May 07 '16 at 16:32
  • I changed JAVA_HOME in `/etc/init/tomcat.conf` to `/usr/bin/jvm/java-8-oracle´, but when I launch Tomcat from Eclipse, it outputs `May 07, 2016 7:01:04 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Java Home: /usr/lib/jvm/java-7-oracle/jre`. Why? (obviously that the problem still persists). – Klue May 07 '16 at 17:03
  • what do you get when you launch "which java"? Have you tried to launch it manually using startup.sh as described in the like that I provide in my answer? – Nicolas Filotto May 07 '16 at 18:06
  • The problem was with Eclipse settings of Tomcat 8. Though I was changing tomcat.conf, still the version 1.7 was used due to Server settings in Eclipse. I will accept your answer if you add this detail. – Klue May 07 '16 at 18:17
  • if you find it by yourself simply add your answer and accept it – Nicolas Filotto May 07 '16 at 18:24