使用ant脚本,对java web项目,编译、打包、发布部署到tomcat
2014-11-09 21:46
921 查看
javac默认使用jdk进行编译。当项目中有
这种类型时,ant编译不能通过。必须使用eclipse jdt进行编译。
指定使用jdt进行编译,两种方法都可以。
一是定义build.compiler属性:
二是在javac中指定参数compiler="org.eclipse.jdt.core.JDTCompilerAdapter"。
如果项目中没有那样的泛型代码,不需要指定编译器。
之后,在ant eclipse 插件里面,运行ant脚本,还需要如下设置:
在build.xml上点右键 --- Run as --->
External Tools Configurations .然后点JRE.选中第一项,然后点击Run。
或者在eclipse ant插件界面,点lmx即项目名称,run as,也是一样。
之后再运行ant,就无需再这样设置。直接运行就可。
<T> T <X> X
这种类型时,ant编译不能通过。必须使用eclipse jdt进行编译。
指定使用jdt进行编译,两种方法都可以。
一是定义build.compiler属性:
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
二是在javac中指定参数compiler="org.eclipse.jdt.core.JDTCompilerAdapter"。
如果项目中没有那样的泛型代码,不需要指定编译器。
<?xml version="1.0" encoding="UTF-8"?> <project name="lms" default="deploy" basedir="D:/workspace/lms"> <property environment="env" /> <property name="webapp.name" value="lms" /> <property name="catalina.home" value="D:/developer/apache-tomcat-6.0.32" /> <property name="dist.dir" value="${basedir}/dist" /> <property name="ant.dir" value="D:/developer/apache-ant-1.8.3" /> <property name="webRoot.dir" value="${basedir}/webapp" /> <property name="src.dir" value="${basedir}/src" /> <property name="config.dir" value="${basedir}/resources" /> <property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" /> <property name="build.dir" value="${basedir}/build" /> <!-- 使用eclipse jdt进行编译,而不使用JDK编译 --> <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="on" source="1.6" target="1.6" deprecation="true" debug="true" encoding="UTF-8" classpathref="project.classpath" > <compilerarg line="-Xlint:unchecked" /> <!-- <classpath refid="project.classpath" /> --> </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> <!-- 将class文件打成 jar包 --> <!-- <target name="pack" depends="compile"> <jar jarfile="${build.dir}/${webapp.name}.jar"> <fileset dir="${build.dir}/classes"> <include name="**/*.class"/> </fileset> </jar> </target> --> <!-- 打成war包, 名称默认为 项目名 --> <target name="war" depends="compile" description="将工程打成war包"> <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> <!-- copy war包 tomcat的deploy目录 --> <target name="deploy" depends="war" description="部署项目"> <echo message="begin deploy..." /> <copy file="${dist.dir}/${webapp.name}.war" todir="${catalina.home}/webapps" /> <echo message="end deploy..." /> </target> </project>
之后,在ant eclipse 插件里面,运行ant脚本,还需要如下设置:
在build.xml上点右键 --- Run as --->
External Tools Configurations .然后点JRE.选中第一项,然后点击Run。
或者在eclipse ant插件界面,点lmx即项目名称,run as,也是一样。
之后再运行ant,就无需再这样设置。直接运行就可。
相关文章推荐
- 使用ant脚本,对java web项目,编译、打包、发布部署到tomcat
- 使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
- 使用ANT脚本编译、打包、部署到tomcat,启动、停止tomcat
- 使用Ant给EJB项目编译、打包、发布
- 利用ant从svn更新项目编译打包并发布项目的脚本
- 使用ant编译打包、部署简单的javaweb项目 --01
- 使用ant编译打包、部署简单的javaweb项目 --02
- Apache Ant学习总结(二):使用Ant自动编译JavaWeb项目并打成war包发布到Tomcat中
- 全自动的使用ANT编译,打包EJB项目,并且部署到Websphere服务器上面
- 使用ant脚本编译web工程并自动部署到tomcat
- Ant 对struts2+Ibatis+Spring3的项目编译,打包,发布到Tomcat
- Hudson之——Hudson的使用(使用 Hudson 来自动化编译、分析、打包、发布、部署项目)
- (转)Android使用ant对项目进行编译签名优化打包
- Android_使用ant对项目进行编译签名优化打包
- Java Web应用中使用ANT在线编译不用重起tomcat的方法
- App自动化之使用Ant编译项目多渠道打包
- 使用ant编译和发布java项目
- [转]Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
- 使用ANT编译--实现外部传参(多渠道替换)、批处理打包------第二步什么是ANT,如何使用ANT命令为Android项目打包
- ant+ivy完成项目初始化,编译,单元测试,打包,部署