10

In linux, is it possible to have a web application written using Java 7 be deployed on tomcat6? If so, what configuration needs to be modified to allow it to work?

I have tried changing the JAVA_HOME variable in the tomcat6.conf file and restarting, but it is still using 1.6 according to the tomcat manager webpage, and only applications written in 1.6 or lower deploy correctly.

I have both jdk 1.6 and 1.7 installed in different locations.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Zero
  • 1,147
  • 1
  • 9
  • 13
  • 1
    Not sure what the `tomcat6.conf` file is supposed to be, I have never seen that. You might want to check if there is a `setenv` batch/shell script in the `bin` directory that sets the JAVA_HOME variable –  Mar 06 '12 at 22:21
  • 2
    Tomcat 6 does not officially support JDK 7 (and based off all the error reports I doubt you would want to try to get it too work with it). Either compile your application with 1.6 compatibility mode or upgrade to Tomcat 7. – Perception Mar 06 '12 at 22:22

4 Answers4

9

I had a major problem when I compiled my servlet using java JDK 1.7.0, Tomcat wouldn't start up due of a runtime manor.major version error.

To make Tomcat6 run your classes using JDK 1.7 do the following:

  1. Open the file /etc/init.d/tomcat6 with root privilege.

  2. You will find a variable called JDK_DIRS at line 83.

  3. Comment it out by adding # at the beginning of the line.

  4. Write the following bellow it: JDK_DIRS="/usr/lib/jvm/java-1.7.0-openjdk-i386"

  5. Save and restart tomcat

Ramzi Komati
  • 176
  • 2
  • 5
4

I'm just using default Tomcat installations without setting up any config files except the tomcat-users.xml for GUI login.

Apache Tomcat 6.0.35 and 6.0.16 are each running on JVM 1.7.0_03-b05 (Windows+Linux).

JAVA_HOME must point to the JDK folder; e.g.:

C:\Program Files\Java\jdk1.7 (Windows)

or

/usr/lib/jvm/java-6-sun (Ubuntu, this link points to JDK installation)

skaffman
  • 398,947
  • 96
  • 818
  • 769
eldiamo
  • 111
  • 8
  • The problem isnt running tomcat directly using Java 1.7, thats fine. The problem is, which version tomcat uses to launch the servlets with. The question asks how to get tomcat to use Java 1.7 to launch its servlets, not whether you can launch tomcat itself on Java 1.7, which obviously works fine. – Zero Sep 24 '12 at 15:56
3

I have run into similar problem and it seems that JDK 1.7 doesn't have backward compatibility with Tomcat 6. You need to deploy it to Tomcat 7 or recompile using JDK 1.6.

skaffman
  • 398,947
  • 96
  • 818
  • 769
aretai
  • 1,619
  • 6
  • 19
  • 30
  • 3
    That sounds rather unlikely to me. Do you have anything to back that up with? – skaffman May 08 '12 at 15:19
  • 2
    Tomcat itself runs fine on 1.6, but the question is about the version tomcat uses to launch instances of servlets. Tomcat 6 itself will not run a servlet written in Java 1.7. – Zero May 11 '12 at 03:11
  • This answer should *not* be the best answer as it can be misleading. Java 7 DOES run on Tomcat 6. (Just pay attention to what @Zero is saying) – Junho Park Dec 18 '13 at 17:13
  • @JunhoPark I updated my selection for the answer, although I am not currently in a position to test whether 1.7 servlets run in a tomcat 6 instance using the modifications from Ramzi Komati. I will take your word for it. – Zero Dec 23 '13 at 14:12
1

I found it made a difference which Java 7 was used by Tomcat 6.

#JAVA_HOME=/usr/lib/jvm/java-7-openjdk  ## Did not work
JAVA_HOME=/usr/lib/jvm/java-7-oracle    ## DID WORK

By "Did not work", I specifically mean, on booting up my webapp I got ClassNotFoundException: java.lang.AutoCloseable. This interface is new with Java 7.

Caused by: java.lang.NoClassDefFoundError: java/lang/AutoCloseable
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:751)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
    ... 47 more
Caused by: java.lang.ClassNotFoundException: java.lang.AutoCloseable
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
        ... 58 more
Stewart
  • 17,616
  • 8
  • 52
  • 80