Java 使用 maven 构建时目标版本无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18626490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid target release when building with maven
提问by 0x56794E
I recently upgrade my machine to the latest version of java 6, and keep getting this error when building the project. Does anyone what this means?
我最近将我的机器升级到最新版本的 java 6,并且在构建项目时不断收到此错误。有没有人这是什么意思?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project
biz.minaret: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.6.0_45
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
Part of my pom looks like this
我的 pom 的一部分看起来像这样
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.6.0_45</source>
<target>1.6.0_45</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
My JAVA_HOME is properly set:
我的 JAVA_HOME 设置正确:
PS C:\Users\me\Documents\m
PS C:\Users\me\Documents\m
Documents\myproject> java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)>
And:
和:
Documents\myproject> javac -version
javac 1.6.0_45
采纳答案by khmarbaise
You should use things like 1.6
or 1.7
without build numbers.
您应该使用类似1.6
或1.7
不使用内部版本号的东西。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
The encoding part should be solved by using the following properties:
编码部分应该通过使用以下属性来解决:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
After you have defined that you can simplyfied the above configuration to the following
定义好之后就可以把上面的配置简单的变成下面这样
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
回答by Prasad Tamgale
Instead of modifying the pom.xml
file with specific source and target version in configuration tab, just specify it via an environment variable.
无需pom.xml
在配置选项卡中使用特定的源和目标版本修改文件,只需通过环境变量指定它。
Use this command:
使用这个命令:
mvn clean install -Denv.JAVA_7_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
This will solve the error definitely.
这肯定会解决错误。
Thanks,
谢谢,
Prasad
普拉萨德