Maven问题:-source 1.5 [ERROR]中不支持switch中的字符串(使用-source 7或更高版本来启用switch中的字符串)

时间:2018-08-22 11:58:04

标签: java maven

当我尝试编译我的Maven时,出现以下错误:

strings in switch are not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable strings in switch)

它抱怨切换。见图片。 我还附加了POM.XML。

enter image description here

1 个答案:

答案 0 :(得分:2)

Switch作为参数的

string仅受Java 1.7或更高版本支持。您使用目标版本1.5(这是maven的默认版本)进行编译。

在pom中添加以下几行:

  <properties>
    <maven.compiler.source><Java_version></maven.compiler.source>
    <maven.compiler.target><Java_version></maven.compiler.target>
  </properties>

例如<Java_version>为1.7或更高

  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

有关更多信息,请参见https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html