我有一个使用Maven 3.2.1
和Java 1.7
的项目。
当我使用maven maven clean install
构建此项目时,我将错误视为
error: strings in switch are not supported in -source 1.5
它抱怨的代码是
final String activeProfile = environment.getActiveProfiles()[0];
switch (activeProfile) {
case "integration":
DataSetupTest.liquibaseUpdate(entityManager, true);
break;
case "default":
DataSetupTest.liquibaseUpdate(entityManager, false);
break;
default:
throw new RuntimeException(activeProfile + " is not a recognized @Profile");
}
我确认maven
和java
的版本为
maven
$ mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T09:37:52-08:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.7.0_55, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.3", arch: "x86_64", family: "mac"
java
$ java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
我做错了什么?
更新
感谢快速指点。我在source
中不使用target
或pom.xml
,但我强制将java版本>=1.7
强制为
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.7,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
加号JAVA_HOME
正确指向1.7
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home