Upgrading Tomcat and Eclipse to J2SE 5.0

I just finished upgrading one of my apps to J2SE 5.0. The docs on this are somewhat fragmented so here is a step by step guide for upgrading Tomcat and Eclipse to this version of the JVM.

Assuming you're on Tomcat 5.5 and Eclipse 3.1

1. Download J2SE 5.0 form Java/Sun site and install.
2. Change Tomcat's classpath to use the new compiler:
- On Windows, this can be done by opening 'Configure Tomcat' from the Start Menu/Apache Tomcat 5.5 menu, clicking on the 'Java' subtab and changing the JVM location.
- On Linux, you can do this by just changign the JAVA_HOME env var for the user that starts/stops tomcat.
3. In Eclipse, Open Window->Preferences, then click on Java/Compiler in the preferences menu. Change the 'Compiler Compliance Level' to 5.0
4) Check your build.xml (assuming you're using ant to build) and make sure that you have the following parameter set correctly: source="1.5"
5) Do a full build and test your app!

Next, if you'd like to use 5.o features in your JSP files:

6) add tools.jar from your JAVA_HOME/lib directory to TOMCAT_HOME/common/lib
7) Remove jasper-compiler-jdt.jar from the TOMCAT_HOME/common/lib dir and replace with ant.jar. I used Version 1.6.5 available from the Ant/Apache website.
8) You'll need to edit your web.xml file in TOMCAT_HOME/conf and add the params in red.

<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>


9) Restart tomcat (Better safe than sorry)

Done!

No comments:

Post a Comment

Comments on this blog are moderated and we do not accept comments that have links to other websites.

Share

About Isaac Sacolick

Isaac Sacolick is President of StarCIO, a technology leadership company that guides organizations on building digital transformation core competencies. He is the author of Digital Trailblazer and the Amazon bestseller Driving Digital and speaks about agile planning, devops, data science, product management, and other digital transformation best practices. Sacolick is a recognized top social CIO, a digital transformation influencer, and has over 900 articles published at InfoWorld, CIO.com, his blog Social, Agile, and Transformation, and other sites. You can find him sharing new insights @NYIke on Twitter, his Driving Digital Standup YouTube channel, or during the Coffee with Digital Trailblazers.