Maven: javac: source release 1.6 requires target release 1.6

后端 未结 6 1076
说谎
说谎 2020-12-08 04:48

NOTE: This appears to be a limit in the \"javac\" program.

I have Java 6 code that needs to be built for a Java 5 JVM. My previous work with the javac ant target (

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 05:47

    I believe you need to set -bootclasspath as well so that javac compiles against JDK 1.5 bootstrap classes.

    Try:

    javac -source 1.6 -target 1.5 -bootclasspath /path/to/jdk1.5/lib/rt.jar -extdirs "" Foo.java
    

    UPDATE:

    Try removing the -source option, but keep the -target option.

    I just tested it out:

    # no source, only target => COMPILES to 1.5
    $ javac -target 1.5 Foo.java
    $ javap -v  Foo | grep version
      minor version: 0
      major version: 49
    
    # no source, no target => COMPILES to 1.6
    $ javac Foo.java
    $ javap -v  Foo | grep version
      minor version: 0
      major version: 50
    
    # both source and target => ERROR
    $ javac -source 1.6 -target 1.5 Foo.java
    javac: source release 1.6 requires target release 1.6
    
    $ javac -version
    javac 1.6.0_21
    

提交回复
热议问题