How to change Ant compiler to JDK 1.6

前端 未结 5 627
天涯浪人
天涯浪人 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:22

    I thought it would be nice to add an updated answer to this question, since I recently dealt with a lot of headaches surrounding this same issue. My specific use case: My computer uses JRE1.8, but I needed ant to target JRE1.7 running on the server. The trick for me was to use the following attributes in combination (referencing the documentation):

    • srcdir: Location of the java files.
    • destdir: Location to store the class files.
    • includeantruntime: Whether to include the Ant run-time libraries in the classpath. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run.
    • source: Java language features accepted by compiler
    • target: Generate class files for specific JVM version (cross-compile).
    • fork: Whether to execute javac using the JDK compiler externally.
    • compiler: The compiler implementation to use.

    You don't have to specify the executable file unless you have really specific dependencies (e.g. more recent enterprise version as opposed to latest free version).

    Example:

    
    
    

提交回复
热议问题