java 从命令运行 ant 脚本,发生错误:找不到类:org.eclipse.jdt.core.JDTCompilerAdapter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10509138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run ant script from command,error happened:Class not found: org.eclipse.jdt.core.JDTCompilerAdapter
提问by Lena
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.
在我的java web项目中,有类似的代码<T>
,在ant脚本中,javac使用JDK编译java代码,编译不成功。
Later,I know it must use eclipse JDT to compile.
后来,我知道它必须使用eclipse JDT来编译。
And, in eclipse, ant script can run success.when run like this:
并且,在 eclipse 中,ant 脚本可以运行 success.when 像这样运行:
Right key click build.xml ---> Run ---> Run as ---> External Tools Configurations,click JRE,select "Run in the same JRE as the workspace".
右键单击build.xml ---> Run ---> Run as ---> External Tools Configurations,点击JRE,选择“Run in the same JRE as the workspace”。
After that, ant can run successful, in eclipse.
之后,ant就可以在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
但是,我想写一个 .bat 和 .sh 文件来调用 ant 脚本,编译、War、部署和启动 Tomcat。所以,ant 应该从命令运行。我尝试了更多,错误总是发生:找不到类:org.eclipse.jdt.core.JDTCompilerAdapter
PS, I have copy jar files about JDT in eclipse plugin to ant_home/lib directory.
PS,我已经将eclipse插件中关于JDT的jar文件复制到ant_home/lib目录下。
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>
`
`
采纳答案by Pradeep
Don't use the ant from eclipse IDE for usage from command line.
不要将 Eclipse IDE 中的 ant 用于命令行。
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.
单独下载 ant 并将其解压缩到类似 - C:\apache\ant - 对于 Windows 的位置,并将其 bin 目录放在您的 PATH 中。它会附带一些 jars,这些 jars 也需要添加到您的 CLASSPATH 中。
For Mac OSX 'sudo port install ant" takes care of everything.
对于 Mac OSX,“sudo port install ant”会处理一切。
回答by WENPIN YEH
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.)
从 Eclipse 下载 ecj*.jar 并放在 ANT_HOME/lib 下。确保在 shell 环境下设置了 ANT_HOME,或者您应该在 shell 的 CLASSPATH 中设置 ecj*.jar。(否则,一个 Class not found: org.eclipse.jdt.core.JDTCompilerAdapter 可能仍会被抛出。)
回答by Patrice M.
For the record, I am also getting this error randomly (works more often than not) when using the <javac>
task with that compiler adapter in a <parallel>
context, i.e. in multi-threaded situation.
作为记录,<javac>
在<parallel>
上下文中(即在多线程情况下)使用带有该编译器适配器的任务时,我也会随机收到此错误(经常工作)。
It looks as if the compiler adapter jar is temporarily locked and can't be accessed by the thread classloader or something. I don't have a workaround for it yet, short of removing the <parallel>
execution.
看起来好像编译器适配器 jar 被临时锁定,线程类加载器或其他东西无法访问。除了删除 <parallel>
执行之外,我还没有解决方法。