使用 Maven 和 Netbeans 为 1.6 编译 java 源 1.7 [英] compile java source 1.7 for 1.6 with Maven and Netbeans
问题描述
我有一个为 java 1.7 编写的源代码.我想为 java 1.6 编译它.如果我理解正确,我需要使用选项 -source 1.7 -target 1.6
I have a source code written for java 1.7. I would like to compile it for java 1.6. If I understood correctly, I need to use the options -source 1.7 -target 1.6
我正在使用 Maven2 和 Netbeans (8.0).所以,我试过了:
I am using Maven2 and Netbeans (8.0). So, I tried :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.6</target>
<compilerArguments>
<bootclasspath>/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
但我得到一个 javacTask: source release 1.7 requires target release 1.7
我读到有些人使用 eclipse 编译器来使其工作,但是如果我使用的是 Netbeans,我该怎么做?
I read that some people use eclipse compiler to make it work, but how can I do this if I'm using Netbeans ?
非常感谢您的帮助
推荐答案
EDIT 抱歉,情况正好相反.您可以编译源 1.6 和目标 1.7,但是当源版本 > 目标版本时不能编译它,因为这样它无法处理语言的新功能.
EDIT Sorry it's the other way around. You can compile source 1.6 and target 1.7 but you can't compile it when source version > target version because then it couldn't handle new features of the language.
有关这方面的更多详细信息,请参阅 javac 文档中的交叉编译选项 http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html.
For more detail about this see Cross-Compilation Options in javac documentation http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html.
如果你有 1.6 源代码,你可以像这样为目标版本 1.7 编译它们:
If you would have 1.6 sources you could compile them for target version 1.7 like this:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>>
这篇关于使用 Maven 和 Netbeans 为 1.6 编译 java 源 1.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!