0

I have recently upgraded my development machine to Ubuntu 18.04 and have been revisiting and checking some old projects, one of which is built under Eclipse oxygen and deployed using Tomcat 7.

To the best of my memory this project worked when deploying the .war file to the private instance of tomcat (running on port 10080) and the main, autostarting instance on 8080.

It still works on 10080 but when I deploy to 8080 and open through a browser, I see

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/compiler/env/INameEnvironment : Unsupported major.minor version 52.0

I have $JAVA_HOME as JAVA_HOME="/usr/lib/jvm/java-8-oracle"

The main tomcat manager page shows :

Apache Tomcat/7.0.68 (Ubuntu) JVM version 1.7.0_80-b15

I have set the the eclipse compiler compliance level to 1.7.

I am completely baffled as to why one instance is OK and the other not. I don't want to change the JAVA_HOME, so I think it must be something to do with the tomcat configuration or the internal compiler but can't seem to sort it out.

All sensible suggestions will be gratefully received.

Edit:

This is not a duplicate of a question, as I have built one war file and exported it to ~/junk. After that I have copied and pasted it to the separate webapps folders for the two Tomcat instances. I think it's a tomact configuration issue but I can't see what. Please don't mark it as duplicate

Edit 2:

Looking at how the tomcat was started as a service with systemctl I see:

nick@nick-X555LAB:~$ systemctl status tomcat7.service 
tomcat7.service - LSB: Start Tomcat.
   Loaded: loaded (/etc/init.d/tomcat7; generated)
   Active: active (running) since Mon 2018-08-20 12:04:29 BST; 55s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10050 ExecStart=/etc/init.d/tomcat7 start (code=exited, status=0/SUCC
    Tasks: 20 (limit: 4915)
   CGroup: /system.slice/tomcat7.service
           └─10109 /usr/lib/jvm/java-7-oracle/bin/java -Djava.util.logging.confi

Aug 20 12:04:24 nick-X555LAB systemd[1]: Starting LSB: Start Tomcat....
Aug 20 12:04:24 nick-X555LAB tomcat7[10050]:  * Starting Tomcat servlet engine t
Aug 20 12:04:29 nick-X555LAB tomcat7[10050]:    ...done.
Aug 20 12:04:29 nick-X555LAB systemd[1]: Started LSB: Start Tomcat..

Note the reference to java7 - I'd like to switch this to java 8


Solved

Solved it. Found a reference to java 7 in /etc/default/tomcat7, changed it to java 8 and all is well.

Community
  • 1
  • 1
NickT
  • 23,844
  • 11
  • 78
  • 121
  • It seems that one instance is running on Java 8, while the other is running on Java 7. – Henry Aug 20 '18 at 09:43
  • @Jens Question edited, with reason not to mark as duplicate, so reopen it please – NickT Aug 20 '18 at 10:22
  • @Henry both startup.sh show : Using JRE_HOME: /usr/lib/jvm/java-8-oracle when invoked – NickT Aug 20 '18 at 10:24
  • What is this then? `Apache Tomcat/7.0.68 (Ubuntu) JVM version 1.7.0_80-b15` – Henry Aug 20 '18 at 11:33
  • The reference to 1.7 is what I'm looking at now. It seems to be specific to the way that tomcat starts a service, I shall grep -r for /usr/lib/jvm/java-7-oracle/bin/java – NickT Aug 20 '18 at 12:09
  • _"This is not a duplicate of a question"_ It is. You have compiled your code targeting Java 8, or are using a library targeting Java 8 and trying to run it on an earlier Java version. That cannot work, and as explained by the duplicate, you will either need to use Java 8 or make sure your code and all libraries you use were compiled for a lower Java version. – Mark Rotteveel Aug 20 '18 at 13:56
  • It is not a duplicate, because one war file runs on the private tomcat under JRE 8. I am trying to get the main tomcat to use java 8 JVM but it is sticking to java 7, as described in the second edit. I want to change it in tomcat but can't seem to find a way. That's the question I'm asking. If you can help with this, please do so, otherwise keep quiet. – NickT Aug 20 '18 at 14:02
  • NickT - take a look a [this post](https://askubuntu.com/questions/272187/setting-jdk-7-as-default/272190) - Ubuntu has it's own way of setting the "default" JVM. The question is to set it to Java 7 but it shows the way to change to others. – stdunbar Aug 20 '18 at 14:56
  • Solved it, see edit 3 – NickT Aug 21 '18 at 15:33

1 Answers1

0

Use update-alternatives to change the default JDK to java8 as

sudo update-alternatives --config java

see https://linux.die.net/man/8/update-alternatives

Yu Jiaao
  • 4,444
  • 5
  • 44
  • 57