When running our Maven build, a member of my team gets this error when executing. However, when we run java -version
from her command line, it indicates Java 1.6.0_26. The error obviously seems to be screaming that Maven is using Java 5.
运行我们的Maven构建时,我的团队成员在执行时会收到此错误。但是,当我们从她的命令行运行java -version时,它表示Java 1.6.0_26。 Maven正在使用Java 5,这个错误显然似乎在尖叫。
How do I figure out and change what version of Java is being used by Maven?
我如何找出并更改Maven正在使用的Java版本?
3 potentially important notes:
3个可能重要的说明:
- This is executed at the command line, not using Eclipse plugin
- 这是在命令行执行的,而不是使用Eclipse插件
- JAVA_HOME is set to a Java 1.6 JDK
- JAVA_HOME设置为Java 1.6 JDK
- Using Maven 2.2.1
- 使用Maven 2.2.1
4 个解决方案
#1
61
mvn -version
will output which java it's using. If JAVA_HOME is set to a valid JDK directory and Maven is using something else, then most likely someone has tampered with the way that Maven starts up.
mvn -version将输出它正在使用的java。如果将JAVA_HOME设置为有效的JDK目录并且Maven正在使用其他内容,则很可能有人篡改了Maven启动的方式。
#2
7
You will need to configure maven-compiler-plugin
to use 1.6 source
and target
parameters ( by default it is 1.5 ).
您需要配置maven-compiler-plugin以使用1.6源和目标参数(默认情况下为1.5)。
This is the best done in your project's parent pom in <pluginManagment>
section ( but you can always configure it per individual projects of course ).
这是在
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
#3
1
Look here: http://www.MacAdie.net/2011/07/10/adding-some-xml-to-netbeans-pom-files/
请看这里:http://www.MacAdie.net/2011/07/10/adding-some-xml-to-netbeans-pom-files/
#4
1
mvn -version
tells you what compiler Maven is using, so this answers the question unless your POM specifies override values for the versions to be used.
mvn -version告诉你Maven正在使用什么编译器,所以除非你的POM为要使用的版本指定覆盖值,否则它会回答这个问题。
Here's the easiest way to specify the overrides in pom.xml
:
这是在pom.xml中指定覆盖的最简单方法:
<properties>
<maven.compiler.target>1.9</maven.compiler.target>
<maven.compiler.source>1.9</maven.compiler.source>
</properties>
Alternatively, the maven-compiler-plugin
can be specified more explicitly. In that case, look at the <source>
and <target>
values associated with the plugin.
或者,可以更明确地指定maven-compiler-plugin。在这种情况下,请查看与插件关联的
Both of these options are described here.
这两个选项都在这里描述。
If your POM has a <parent>
, then you need to check that as well (recursively).
如果你的POM有
Note: When source
and target
are specified, these values are passed as command-line options to the compiler. Using this feature, you can compile or run against earlier Java versions than the compiler's nominal value.
注意:指定source和target时,这些值将作为命令行选项传递给编译器。使用此功能,您可以编译或运行早于Java版本而不是编译器的标称值。
#1
61
mvn -version
will output which java it's using. If JAVA_HOME is set to a valid JDK directory and Maven is using something else, then most likely someone has tampered with the way that Maven starts up.
mvn -version将输出它正在使用的java。如果将JAVA_HOME设置为有效的JDK目录并且Maven正在使用其他内容,则很可能有人篡改了Maven启动的方式。
#2
7
You will need to configure maven-compiler-plugin
to use 1.6 source
and target
parameters ( by default it is 1.5 ).
您需要配置maven-compiler-plugin以使用1.6源和目标参数(默认情况下为1.5)。
This is the best done in your project's parent pom in <pluginManagment>
section ( but you can always configure it per individual projects of course ).
这是在
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
#3
1
Look here: http://www.MacAdie.net/2011/07/10/adding-some-xml-to-netbeans-pom-files/
请看这里:http://www.MacAdie.net/2011/07/10/adding-some-xml-to-netbeans-pom-files/
#4
1
mvn -version
tells you what compiler Maven is using, so this answers the question unless your POM specifies override values for the versions to be used.
mvn -version告诉你Maven正在使用什么编译器,所以除非你的POM为要使用的版本指定覆盖值,否则它会回答这个问题。
Here's the easiest way to specify the overrides in pom.xml
:
这是在pom.xml中指定覆盖的最简单方法:
<properties>
<maven.compiler.target>1.9</maven.compiler.target>
<maven.compiler.source>1.9</maven.compiler.source>
</properties>
Alternatively, the maven-compiler-plugin
can be specified more explicitly. In that case, look at the <source>
and <target>
values associated with the plugin.
或者,可以更明确地指定maven-compiler-plugin。在这种情况下,请查看与插件关联的
Both of these options are described here.
这两个选项都在这里描述。
If your POM has a <parent>
, then you need to check that as well (recursively).
如果你的POM有
Note: When source
and target
are specified, these values are passed as command-line options to the compiler. Using this feature, you can compile or run against earlier Java versions than the compiler's nominal value.
注意:指定source和target时,这些值将作为命令行选项传递给编译器。使用此功能,您可以编译或运行早于Java版本而不是编译器的标称值。