Setting the target version of Java in ant javac

前端 未结 4 993
轮回少年
轮回少年 2020-12-02 21:40

I need to compile a jar file using ant (1.7.0) to run under a specific version of Java (1.5). I currently have Java 1.6 on my machine. I have tried setting:

         


        
相关标签:
4条回答
  • 2020-12-02 22:32

    Use "target" attribute and remove the 'compiler' attribute. See here. So it should go something like this:

    <target name="compile">
      <javac target="1.5" srcdir=.../>
    </target>
    

    Hope this helps

    0 讨论(0)
  • 2020-12-02 22:38

    Both source and target should be specified. I recommend providing ant defaults, that way you do not need to specify source/target attribute for every javac task:

    <property name="ant.build.javac.source" value="1.5"/>
    <property name="ant.build.javac.target" value="1.5"/>
    

    See Java cross-compiling notes for more information.

    0 讨论(0)
  • 2020-12-02 22:39

    You may also set {{ant.build.javac.target=1.5}} ant property to update default target version of task. See http://ant.apache.org/manual/javacprops.html#target

    0 讨论(0)
  • 2020-12-02 22:45

    To find the version of the java in the classfiles I used:

    javap -verbose <classname>
    

    which announces the version at the start as

    minor version: 0
    major version: 49
    

    which corresponds to Java 1.5

    0 讨论(0)
提交回复
热议问题