unludo
unludo

Reputation: 5010

Does Tomcat 8 support Java 8?

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:

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.

Upvotes: 31

Views: 58563

Answers (7)

Shubhra Sinha
Shubhra Sinha

Reputation: 47

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>

Upvotes: 2

Ankit
Ankit

Reputation: 603

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.

Upvotes: 0

Chewy
Chewy

Reputation: 651

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

Upvotes: 5

Stan Sokolov
Stan Sokolov

Reputation: 2260

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

Upvotes: 2

Denis Makarskiy
Denis Makarskiy

Reputation: 699

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!

Upvotes: 10

Raja Asthana
Raja Asthana

Reputation: 2100

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

Upvotes: 3

Deividi Cavarzan
Deividi Cavarzan

Reputation: 10110

According to the Tomcat Docs:

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

Upvotes: 33

Related Questions