31

Is tomcat 8 (today as RC1 - see this) supporting Java 8, even if it is still in beta?

Among others Tomcat 8 supports Java EE 7:

  • Websockets
  • Servlet api 3.1 (Asynch servlet support)

I had trouble in the past with Tomcat 7 / Java 7, that's why I am asking this question.


Update

An interesting article on infoq indicates that tomcat 8 is ready for java 8. Even Tomcat 7 would be.

See the article here


If you see any compatibility issue, I will report it here.

Community
  • 1
  • 1
unludo
  • 4,912
  • 7
  • 47
  • 71

7 Answers7

33

According to the Tomcat Docs:

Any installed Java 7 or later JRE (32-bit or 64-bit) may be used.

Jeremiah Orr
  • 2,620
  • 1
  • 18
  • 24
Deividi Cavarzan
  • 10,034
  • 13
  • 66
  • 80
10

Tested Tomcat 7.0.50 with Web app written on Java 8 + Spring 4.0.2, using lambda expressions, method references and streams - works like a charm!

Denis Makarskiy
  • 679
  • 9
  • 22
  • Maybe... or not. Tomcat officially supports Java 7, not Java 8. – l.cotonea Jul 15 '14 at 17:55
  • 1
    I wrote about my real expirience. Officialy - yes, the site of Tomcat tell that Java 7 and later versions supported. – Denis Makarskiy Jul 16 '14 at 11:02
  • Depends on the tomcat7 version. The version on ubuntu repositories seems to have some problems. But 7.0.50 should be ok. – digao_mb Sep 15 '14 at 03:16
  • But if you are using Mojarra 2.1 (2.1.29 I have tested) and even with Tomcat 7.0.68 (TomEE 1.7.4 tested) you can not use lambda expressions. Otherwise the following exception will be raised: INFO: Initializing Mojarra 2.1.29 ( 20140702-1445 https://svn.java.net/svn/mojarra~svn/tags/2.1.29@13392) for context '/reflex' márc. 23, 2016 7:10:35 DU org.apache.openejb.server.cxf.rs.CxfRsHttpListener configureFactory ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 18 at position 41 ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 42 – Miklos Krivan Mar 23 '16 at 19:33
5

It does not support out of the box. You must make some changes. in apache home\conf\web.xml add the following lines in the jsp section.

<init-param>
    <param-name>compiler</param-name>
    <param-value>modern</param-value>
</init-param>
<init-param>
    <param-name>compilerSourceVM</param-name>
    <param-value>1.8</param-value>
</init-param>
<init-param>
    <param-name>compilerTargetVM</param-name>
    <param-value>1.8</param-value>
</init-param>
<init-param>
    <param-name>suppressSmap</param-name>
    <param-value>true</param-value>
</init-param>

I also added to my classpath in setenv.sh (or bat) the follwing entry: export CLASSPATH=$JAVA_HOME/lib/tools.jar:$CLASSPATH

Note that I also need to have java_home set to 1.8 (little bit of a duh here, but may be worth mentioning)

Here are some sources: http://tomcat.apache.org/tomcat-8.0-doc/jasper-howto.html http://mail-archives.apache.org/mod_mbox/tomcat-dev/201301.mbox/%3C7CF0788AAB53854AB15567D68F41960238297F32@CH1PRD0410MB369.namprd04.prod.outlook.com%3E

Chewy
  • 651
  • 6
  • 21
3

Tomcat 8.0 is designed to run on Java 7. For reference, the following specifications have been supported:

  1. Tomcat 6: Servlet 2.5, JSP 2.1, and EL 2.1.
  2. Tomcat 7: Servlet 3.0, JSP 2.2, and EL 2.2.
  3. Tomcat 8: Servlet 3.1, JSP 2.3, and EL 3.0. In addition, there is support for a new specification, Java WebSocket 1.0.

See more at: http://blog.gopivotal.com/products/apache-tomcat-8-what-it-is-what-you-need-to-know#sthash.nVw8CTJ9.dpuf

Raja Asthana
  • 2,080
  • 2
  • 19
  • 35
2

I have tried on Linux and it does not work. When it comes to executing a lambda expression in JSP page the following error is thrown

Lambda expressions are allowed only at source level 1.8 or above Apache Tomcat/8.0.14

it runs on JDK jdk1.8.0_25

Stan Sokolov
  • 2,140
  • 1
  • 22
  • 23
2

Thanks Chewy, I was searching for last 1 hour to compile lambdas within jsp it worked for me.

Updated the jsp section in tomcat's web.xml as follows (only this much change was required):

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
        <param-name>compiler</param-name>
        <param-value>modern</param-value>
    </init-param>
    <init-param>
        <param-name>compilerSourceVM</param-name>
        <param-value>1.8</param-value>
    </init-param>
    <init-param>
        <param-name>compilerTargetVM</param-name>
        <param-value>1.8</param-value>
    </init-param>
    <init-param>
        <param-name>suppressSmap</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>fork</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>xpoweredBy</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>mappedfile</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
  </servlet>
0

you can initialize compile value inside web..xml then you can able to Used Tomcat8.

Tomcat 8: Servlet 3.1, JSP 2.3, and EL 3.0.

Ankit
  • 593
  • 4
  • 12