I'm trying to use the new Java 7 switch on strings feature.
But Tomcat is not cooperating.
I've made sure that tomcat is running under java 7 but it seems that it's not compiling under it.
I've added the following to the web.xml file, under the jsp servlet entry
<init-param>
<param-name>compiler</param-name>
<param-value>C:/Program Files/Java/jdk1.7.0/bin/javac.exe</param-value>
</init-param>
but it doesn't seem to do the trick.
Any tips would be appreciated.
Select the command Project ‣ Project Settings and then the Compile options tab. Select the desired Fix Version and click on OK. ⇒ The change is immediately effective.
To change the compiler version in eclipse you need to go to Windows > Preferences > Java > Compiler. There you will see Compiler Compilation Level where in drop-down you will see all compiler version available in system.
Tomcat compiles it internally to some class file that you're not aware of (its stored internally in Tomcat), Tomcat loads this file in runtime and treats it as a compiled Java class.
Step 1: Right click on selected java project and then click on Properties. Step 2: Click on Java Compiler and then perform the changes. Whenever we change the settings, eclipse rebuilds the project.
We are running Tomcat 6 and had the same problem. Our solution was to:
tomcat/lib/ecj-3.3.1.jar
with ecj-3.7.2.jar
(can be taken from the latest Tomcat 7 release);add this to tomcat/conf/web.xml
...
<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>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param> <!-- this should be added -->
<param-name>compilerSourceVM</param-name>
<param-value>1.7</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.7</param-value>
</init-param> <!-- last added line -->
<load-on-startup>3</load-on-startup>
</servlet>
The simpler alternative is, of course, to install Tomcat 7 but this might not be an option for everyone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With