Running Eclipse Java Compiler with Ant
03 Mar 2016解决Eclipse Java的build.xml
直接ant
找不到org.eclipse.jdt.core.JDTCompilerAdapter
的问题,方法就是去官网下载[JDT Core Batch Compiler]。
比如ecj-4.5.2.jar,直接下载链接需要加参数&r=1
。
然后cp ecj-4.5.2.jar /usr/local/Cellar/ant/1.9.6/libexec/lib/
就可以了(ant的路径自己改)。
Eclipse Java Compiler (EJC) is an incremental compiler that is generally faster than any JDKs. It also fixes some incompatible problems related to JDK6, e.g. http://issues.apache.org/jira/browse/OPENJPA-640. This post is about how to run EJC with an ant target to compile your Java projects.
-
Install Ant 1.7+.
-
Download the latest JDT Core Batch Compiler and put it directly into your $ANT_HOME/lib folder. Or, if you have Eclipse installed, you have the compiler by default: Locate the org.eclipse.jdt.core_xxx.jar in the plugins directory of your Eclipse installation, put that jar file into the $ANT_HOME/lib folder, and at the same time unzip this jar file and make jdtCompilerAdapter.jar available to ant. As an alternative, you can specify the path of the jar file by using the “-lib” flag of ant.
-
You are now ready to test the Eclipse compiler in command line. The key is to direct ant to use EJC by specifying the compiler parameter -Dbuild.compiler to org.eclipse.jdt.core.JDTCompilerAdapter. Go to a Java project and type in:
ant -Dbuild.compiler=org.eclipse.jdt.core.JDTCompilerAdapter -Dant.build.javac.target=1.6 -Dant.build.javac.source=1.6 compile
-
You can also set up an ant target to play around with it:
<target name="-eclipse-compile"> <javac source="1.6" target="1.6" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"> … </javac> </target>
No comments
Comments are closed