[英]compile java source 1.7 for 1.6 with Maven and Netbeans
I have a source code written for java 1.7. 我有一个为Java 1.7编写的源代码。 I would like to compile it for java 1.6. 我想针对Java 1.6进行编译。 If I understood correctly, I need to use the options -source 1.7 -target 1.6 如果我理解正确,则需要使用-source 1.7 -target 1.6选项
I am using Maven2 and Netbeans (8.0). 我正在使用Maven2和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>
But I get a javacTask: source release 1.7 requires target release 1.7
但是我得到了一个javacTask: source release 1.7 requires target release 1.7
I read that some people use eclipse compiler to make it work, but how can I do this if I'm using Netbeans ? 我听说有些人使用eclipse编译器使其工作,但是如果我使用Netbeans怎么办?
Thanks a lot for your help 非常感谢你的帮助
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. 您可以编译源1.6和目标1.7,但是当源版本>目标版本时不能编译它,因为这样它就无法处理语言的新功能。
For more detail about this see Cross-Compilation Options in javac documentation http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html . 有关此内容的更多详细信息,请参见javac文档http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html中的“交叉编译选项”。
If you would have 1.6 sources you could compile them for target version 1.7 like this: 如果您有1.6个源代码,则可以将它们编译为目标版本1.7,如下所示:
<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>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.