compile java source 1.7 for 1.6 with Maven and Netbeans

空扰寡人 提交于 2021-01-29 00:40:27

问题


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

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>

But I get a 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 ?

Thanks a lot for your help


回答1:


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.

For more detail about this see Cross-Compilation Options in javac documentation 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:

<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>>


来源:https://stackoverflow.com/questions/27070163/compile-java-source-1-7-for-1-6-with-maven-and-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!