0

I am trying to integrate my maven project with Tomcat server 8.5. Without integration, everything works fine. I replaced maven-compiler-plugin with tomcat7-maven-plugin in pom.xml and did other configurations. After that mvn install, mvn clean install and mvn tomcat7:deploy everything is failing with below exception.

TestServiceCSV.java:[345,48] strings in switch are not supported in -source 1.5
  (use -source 7 or higher to enable strings in switch)

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)

So clearly the compilation is being performed using java 1.5, whereas my jdk version is 1.8.0_144. Additional details below:

>mvn -version
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T02:58:13-05:00)
Maven home: C:\Maven\apache-maven-3.5.2\bin\..
Java version: 1.8.0_144, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_144\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

>java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

I have set the Installed JRE in Eclipse as the JDK. Also the build path for my project reflects same.

>echo $MAVEN_HOME
C:\Maven\apache-maven-3.5.2

>echo $JAVA_HOME
C:\Program Files\Java\jdk1.8.0_144

Tomcat version 8.5.23

POM.xml entry

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>  
<url>http://localhost:8080/manager/html</url>  
<server>TomcatServer</server>    
<username>admin</username>  
<password>xxxx</password>   
</configuration>
</plugin>

Why could the compilation is being performed on 1.5 instead of the actual version?

Patz
  • 274
  • 2
  • 15
  • Tomcat version 8.5.23. – Patz Nov 14 '17 at 07:44
  • "_I replaced maven-compiler-plugin with tomcat7-maven-plugin_" - **don't**. You have removed the section of the `pom.xml` that told Maven what version of Java to use. Why did you think you needed to _replace_ the compiler plugin rather than just **add** the tomcat plugin? – Boris the Spider Nov 14 '17 at 07:50
  • Thanks, it worked! – Patz Nov 17 '17 at 17:27

1 Answers1

1

Default source level of the compiler plugin is 1.5. The compiler:compile goal is bound to the compile phase of the default lifecycle. You always have to set the source and target levels if you want to use advanced language features from release 6 on.

palek
  • 135
  • 6