简体   繁体   English

使用Maven和Netbeans编译Java Source 1.7 for 1.6

[英]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.

相关问题 在从1.6移动到1.7(基于maven的项目)后,无法在Jetbrains Intellij中使用Java 1.7进行编译 - Unable to compile using Java 1.7 in Jetbrains Intellij after moving from 1.6 to 1.7 (maven based project) Maven:编译包含Java 1.6源代码的aspectj项目 - Maven: compile aspectj project containing Java 1.6 source 为什么这个代码在Java 1.6中编译而在Java 1.7中编译? - Why does this code compile in Java 1.6 but not in Java 1.7? 为什么 Maven 使用 JDK 1.6 但我的 java -version 是 1.7 - Why Maven uses JDK 1.6 but my java -version is 1.7 具有混合Java 1.6和1.7名称空间的Maven ClassNotFoundException - Maven ClassNotFoundException with mixed Java 1.6 and 1.7 name space 带有源1.7(或7)的Java Maven构建失败 - Java maven build failure with source 1.7 (or 7) 使用Java 1.6编译的Maven当前项目,对Java 1.7和1.6有2个依赖关系 - Maven current project compiled with java 1.6 which has 2 dependencies on java 1.7 and 1.6 NetBeans中不提供Java 1.7的源/二进制格式选项 - Source/Binary Format option for java 1.7 not available in netbeans 具有源 1.6 配置的 maven 编译器插件是否识别自 1.7 以来引入的 API? - Does maven compiler plugin with source 1.6 configuration recognise API introduced since 1.7? Java 1.6-&gt; 1.7 JNLP = SIGSEGV - Java 1.6 -> 1.7 JNLP = SIGSEGV
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM