Maven - Use JDK 7 to Compile for JVM 5

后端 未结 5 1009
迷失自我
迷失自我 2021-01-02 02:19

I\'ve been trying to get this to work for a while now but no luck yet.

I want to run with JAVA_HOME pointing to JDK7 but I want to compile a project for

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 02:45

    Previous version of Java we not particularly good at supporting previous versions of Java. For Java 7 it appears to be much better.

    Here is a program which should compile under any version.

    public class Main {
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
    }
    
    $ javac -target 1.7 -source 1.7 Main.java
    $ javac -target 1.6 -source 1.6 Main.java
    warning: [options] bootstrap class path not set in conjunction with -source 1.6
    1 warning
    $ javac -Xbootclasspath:/usr/java/jdk1.6.0_29/jre/lib/rt.jar -target 1.6 -source 1.6 Main.java
    $ javac -Xbootclasspath:/usr/java/jdk1.5.0_22/jre/lib/rt.jar -target 1.5 -source 1.5 Main.java
    $ javac -Xbootclasspath:/usr/java/jdk1.4.0_30/jre/lib/rt.jar -target 1.4 -source 1.4 Main.java
    $ javac -Xbootclasspath:/usr/java/jdk1.3.1_29/jre/lib/rt.jar -target 1.3 -source 1.3 Main.java
    $ javac -Xbootclasspath:/usr/java/jdk1.2.2_017/jre/lib/rt.jar -target 1.2 -source 1.2 Main.java
    $ javac -Xbootclasspath:/usr/java/jdk1.1.8_16/jre/lib/rt.jar -target 1.1 -source 1.2 Main.java
    $ javac -Xbootclasspath:/usr/java/jdk1.1.8_16/jre/lib/rt.jar -target 1.1 -source 1.1 Main.java
    javac: invalid source release: 1.1
    Usage: javac  
    use -help for a list of possible options
    $ javac -Xbootclasspath:/usr/java/jdk1.1.8_16/jre/lib/rt.jar -target 1.0 -source 1.0 Main.java
    javac: invalid target release: 1.0
    Usage: javac  
    use -help for a list of possible options
    

    If you need to compile for a previous version of Java, you need to provide a bootclasspath, ideally for the version of Java you want to compile for. Java 7 appears to be able to support all the way back to Java 1.2

提交回复
热议问题