Run ant script from command,error happened:Class not found: org.eclipse.jdt.core.JDTCompilerAdapter
Solution 1
Don't use the ant from eclipse IDE for usage from command line.
Download ant separately and extract it somewhere like - C:\apache\ant - for windows, and put its bin directory in your PATH. It'll come with some jars that will need to be added to your CLASSPATH too.
For Mac OSX 'sudo port install ant" takes care of everything.
Solution 2
Download ecj*.jar from Eclipse and put in under ANT_HOME/lib. Make sure that ANT_HOME is set under the shell environment or you should set the ecj*.jar in the CLASSPATH on the shell. (Otherwise, a Class not found: org.eclipse.jdt.core.JDTCompilerAdapter might be still thrown.)
Lena
I am a girl from China. I like programming, open source, Linux particularly. And I like english song, film. Besides, Japan cartoon is my hobby. My email: [email protected] Feel free to contact me. Wish to be your friend.
Updated on June 04, 2022Comments
-
Lena almost 2 years
In my java web project,there are code like
<T>
, in ant script, javac use JDK to compile java code, and it can't compile success.Later,I know it must use eclipse JDT to compile.
And, in eclipse, ant script can run success.when run like this:
Right key click build.xml ---> Run ---> Run as ---> External Tools Configurations,click JRE,select "Run in the same JRE as the workspace".
After that, ant can run successful, in eclipse.
But, I want to write a .bat and .sh file to call ant script, to compile,war,deploy and start Tomcat. So, ant should run from command. I tried more, error happend always: Class not found: org.eclipse.jdt.core.JDTCompilerAdapter
PS, I have copy jar files about JDT in eclipse plugin to ant_home/lib directory.
Wish your response. Thanks in advance!
build.xml
`
<tstamp> <format property="build.time" pattern="yyyy-MM-dd" /> </tstamp> <path id="project.classpath"> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> <fileset dir="${catalina.home}/lib"> <include name="*.jar" /> </fileset> <fileset dir="${ant.dir}"> <include name="**/*.jar" /> </fileset> </path> <target name="clear"> <delete dir="${build.dir}" /> <delete dir="${dist.dir}" /> <delete file="${catalina.home}/webapps/${webapp.name}.war" /> <delete dir="${catalina.home}/webapps/${webapp.name}" /> </target> <target name="init" depends="clear"> <mkdir dir="${build.dir}/classes" /> <mkdir dir="${dist.dir}" /> </target> <target name="compile" depends="init"> <echo message="begin compile..." /> <javac srcdir="${src.dir}" destdir="${build.dir}/classes" includeantruntime="false" nowarn="on" source="1.6" target="1.6" deprecation="true" debug="true" encoding="UTF-8" classpathref="project.classpath"> <compilerarg line="-Xlint:unchecked" /> </javac> <copy todir="${build.dir}"> <fileset dir="${src.dir}"> <include name="**/*.xml" /> <include name="**/*.properties" /> <include name="**/*.sql" /> </fileset> <fileset dir="${config.dir}"> <include name="**/*.xml" /> <include name="**/*.properties" /> <include name="**/*.sql" /> </fileset> </copy> <echo message="end compile..." /> </target> <target name="war" depends="compile"> <echo message="begin war..." /> <war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}" webxml="${webRoot.dir}/WEB-INF/web.xml"> <lib dir="${lib.dir}" /> <classes dir="${build.dir}/classes" /> <fileset dir="${webRoot.dir}"> <include name="***.*" /> </fileset> </war> <echo message="end war..." /> </target> <target name="deploy" depends="war"> <echo message="begin deploy..." /> <copy file="${dist.dir}/${webapp.name}.war" todir="${catalina.home}/webapps" /> <echo message="end deploy..." /> </target> </project>
`
-
Lena almost 12 yearsMy ant directory is: D:\developer\apache-ant-1.8.3 I have set ANT_HOME="D:\developer\apache-ant-1.8.3" , and have added %ANT_HOME%\bin to the PATH env. I know, when run ant script in eclipse, it use the ant that is eclipse plugin. and,if I don't set compiler to "org.eclipse.jdt.core.JDTCompilerAdapter", another error will throw: 无法确定 <X>X 的类型参数;对于上限为 X,java.lang.Object 的类型变量 X,不存在唯一最大实例. So, it must use eclipse jdt to compile.
-
Lena almost 12 yearsPradeep,thank you. you see,I have add all the jar in ${ant_home} to CLASSPATH.
-
Lena almost 12 years
<project name="lmsx" default="deploy" basedir="D:/workspace/lms"><property name="ant.dir" value="D:/developer/apache-ant-1.8.3" /><property name="webRoot.dir" value="${basedir}/webapp" /><property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" /> <path id="project.classpath"> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> <fileset dir="${catalina.home}/lib"> <include name="*.jar" /> </fileset> <fileset dir="${ant.dir}"> <include name="**/*.jar" /> </fileset> </path>
-
Pradeep almost 12 yearsI am still not sure why you are forced to use eclipse ant to compile. You need standalone ant if you want to run it from outside eclipse. From within eclipse soem jars are being included that you are not aware of. Try to print the classpath when you run it as eclipse plugin and see what all jars are being used. It is not necessary to depend on eclipse based jars. You may be able to find standalone jars for all cases.
-
Lena almost 12 yearsWhen run ant script in eclipse,it use the ant that is in eclipse plugin.But when run from windows command,I use another ant,it's standalone,in
D:/developer/apache-ant-1.8.3
.It's not that one in eclipse. -
Lena almost 12 yearsPradeep, how to print the classpath in ant script?
<echo>${project.classpath}</echo>
or<echo>project.classpath</echo>
or<echo message="project.classpath"/>
or<echo message="${project.classpath}"/>
, all can't work...I am sorry to trouble you. -
Pradeep almost 12 yearsCheck out - javalobby.org/java/forums/t71033.html and blog.andrewbeacock.com/2005/08/… ... and remove the "jar files about JDT in eclipse plugin to ant_home/lib directory". Can you describe again what's the error you get if you dont use the JDT compiler?
-
Lena almost 12 yearsPradeep.if I don't use the JDT compile, get error:
type parameters of <X>X cannot be determined; no unique maximal instance exists for type variable X with upper bounds X,java.lang.Object
-
Lena almost 12 yearsPradeep,right now,I go to the website you gave me and add print classpath code to build.xml, it works.It shown that all the jars I put in project.classpath is in the classpath.
-
Pradeep almost 12 yearsCheck out this - blog.sarathonline.com/2010/08/…
-
Lena almost 12 yearsPradeep,I am sorry.I can't visit that website.maybe because of the network of the Country.Can you post the content by email? my email: [email protected] thank you very much!
-
Pradeep almost 12 yearsThis link might work - basically looks like there's some difference between eclipse compiler and JDK compiler - stackoverflow.com/questions/1609531/…
-
Lena almost 12 yearsPradeep,I know,must use eclipse compiler.But use JDT to compile, how can I run ant script from command successful? That's the problem.
-
Pradeep almost 12 yearsDownload ecj.jar and put it on your classpath as per help.eclipse.org/galileo/index.jsp?topic=/…
-
Pradeep almost 12 yearsDownload it from here - download.eclipse.org/eclipse/downloads/drops/… ....... or look for a file like org.eclipse.jdt.core_3.5.2.v_981_R35x.jar in your installation and extract ecj.jar from inside this jar file
-
Lena almost 12 yearsPradeep, thanks,response me so many times.this problem have resolved right now.I look for org.eclipse.jdt.core_3.5.2.v_981_R35x.jar in eclipse plugin,and extract jdtCompilerAdapter.jar from it,copy jdtCompilerAdapter.jar to ant_home/lib,then it works.I am so happy.Best wishes with you.