Monday, January 14, 2013

GlassFish 3 Tip of the Day: Using JDK 7 with JSP Code

A question came up on the NetBeans J2EE Mailing List about using JDK 7 with GlassFish 3.1.2. Specifically, they were getting the error:
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6197: An error occurred at line: 4 in the jsp file: /index.jspPWC6199: Generated servlet error:strings in switch are not supported in -source 1.5  (use -source 7 or higher to enable strings in switch)

The fix is quite simple. You must include a glassfish-web.xml file in your project, and set a couple of properties. compilerSourceVM and compilerTargetVM.

Please see the example below for a complete configuration.
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
    <property name="compilerSourceVM" value="7"/>
    <property name="compilerTargetVM" value="7"/>
  </jsp-config>
</glassfish-web-app>

The project will now compile and use JDK7.

1 comments :

Unknown said...

That's a really neat fix John. This is one of the most common errors I have come across while trying to use JDK7 with JSP code. Thanks a lot.

Popular Posts