How to change Ant compiler to JDK 1.6

前端 未结 5 550
天涯浪人
天涯浪人 2020-12-16 03:52

I need to compile my source code to be compatible with jre 1.6. However, when I attempt to set the compiler attribute of the javac task to be javac1.6, ant will still compil

5条回答
  •  时光说笑
    2020-12-16 04:34

    Talking about the basics of Ant, since it requires a JVM to run, it is suffice for it to recognize a JRE for this purpose. However if the build process needs to compile classes then it will be dependent on a Java compiler and if it doesn't find one then the build will fail.

    It is possible to set up Ant to use one of several Java compilers, however I will focus on Oracle's javac for the explanation below. Here are the alternatives ...

    1) If the JRE recognized by Ant for its execution is a sub directory under the JDK, it will raise upto the JDK level and identify the required resources.

    2) If JAVA_HOME environment variable is set pointing to a JVM (not JRE) then ant will be able to compile Java artifacts

    3) Alternatively, as per the Ant documentation, JAVACMD can be set in a batch file specific to the OS (antrc_pre.bat for Windows) placed under your home directory (and not that of Ant) then it will recognize the JVM. Please note JAVACMD should refer to the full path of Java.exe under a bin folder and not of JVM home.

    4) Alternatively the Ant command line can take the list of libraries using -l options. Pass a tools.jar to -l option and it would suffice.

    5) Finally fork attribute of JavaC task can be set as explained above. Keep in mind this is resource intensive and not recommended.

提交回复
热议问题