在进行Jenkins+ant+tomcat编译项目自动化的时候,运行过程中会出现报错:
Unable to load annotation processing manager org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager from classpath.
原因是用ant编译时通过eclipsejdt去编译的,是依赖eclipse或myeclipse里面的插件的,所以需要把eclipse或myeclipse的插件里面的某些jar文件放到ant安装目录的lib文件夹内
在eclipse安装目录搜索jdt,找到
org.eclipse.jdt.annotation_1.1.100.v20160418-1457.jar (注意:下滑杠后面的部分因安装版本不一样是不一样的,只要找下滑杠前面部分跟我写出来的一致就行)
org.eclipse.jdt.annotation_2.1.100.v20170511-1408.jar
org.eclipse.jdt.apt.core_3.5.50.v20170920-0950.jar
org.eclipse.jdt.apt.ui_3.5.0.v20170505-1107.jar
org.eclipse.jdt.compiler.apt_1.3.60.v20171129-1553.jar
org.eclipse.jdt.compiler.tool_1.2.51.v20171122-1403.jar
org.eclipse.jdt.core_3.13.101.v20180215-0725.jar
org.eclipse.jdt.debug.ui_3.8.52.v20180104-1240.jar
下图我红色圈出来的可能没有圈完全
复制完成如下图
复制完成之后再运行就ok了
下面附上我的ant脚本:
<?xml version="1.0" encoding="UTF-8"?> <project name="BPP_JAR_Deploy" default="pack" basedir="."> <property environment="env" /> <property name="webapp.name" value="BPP_JAR_Deploy" /> <property name="catalina.home" value="D:apache-tomcat-7.0.68" /> <property name="dist.dir" value="${basedir}/dist" /> <property name="ant.dir" value="C:apache-ant-1.10.3" /> <property name="webRoot.dir" value="${basedir}/WebRoot" /> <property name="src.dir" value="${basedir}/src" /> <!--<property name="config.dir" value="${basedir}/config" />--> <property name="lib.dir" value="${basedir}/lib" /> <property name="build.dir" value="${basedir}/build" /> <!-- 使用eclipse jdt进行编译 --> <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" /> <!-- 初始化classpath依赖包 --> <path id="project.classpath"> <fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset> <!-- 添加tomcat类路径 --> <fileset dir="${catalina.home}/lib"> <include name="*.jar" /> </fileset> <!-- ant lib包 --> <fileset dir="${ant.dir}"> <include name="**/*.jar" /> </fileset> </path> <!-- get the source compile classpath in a printable form --> <pathconvert pathsep="${line.separator}| |-- " property="echo.path.compile" refid="project.classpath"> </pathconvert> <!-- show classpath jars --> <target name="print_classpath"> <echo message="|-- compile classpath"/> <echo message="| |"/> <echo message="| |-- ${echo.path.compile}"/> </target> <!-- 删除旧目录 --> <target name="clear" description="删除旧文件"> <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" description="初始化目录"> <mkdir dir="${build.dir}/classes" /> <mkdir dir="${dist.dir}" /> </target> <!-- 编译java文件 --> <target name="compile" depends="init" description="编译java文件"> <echo message="begin compile..." /> <javac srcdir="${src.dir}" destdir="${build.dir}/classes" includeantruntime="false" nowarn="false" 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> </copy> <echo message="end compile..." /> </target> <!-- 编译后打jar包 --> <target name="pack" depends="compile"> <jar jarfile="${build.dir}/${webapp.name}.jar"> <fileset dir="${build.dir}/classes"> <include name="**/*.class"/> </fileset> </jar> </target> </project>