今天用apache-ant-1.9.4 版本对 java web项目-adjustSolr 打包为war,并发布到tomcat中(一定要注意开发用的jdk版本和tomcat中的jdk版本一致,否则unsupport version51 错误)
贴build.xml文件的代码
<?xml version="1.0" encoding="UTF-8"?>
<project name ="adjustSolr" default ="war" basedir =".">
<property name="catalina.home" value="D:/tomcat6.5-jdk1.7" />
<property name ="build.dir" value ="build"/>
<property name ="lib.dir" value ="WebContent/WEB-INF/lib"/>
<property name="webRoot.dir" value="WebContent" />
<property name="classes.dir" value="build/classes" />
<path id="project.classpath">
<fileset dir="${lib.dir}" includes="***.jar" />
<!-- 添加tomcat类路径 -->
<fileset dir="${catalina.home}/lib">
<include name="*.jar" />
</fileset>
</path>
<pathconvert pathsep="${line.separator}| |-- "
property="echo.path.compile"
refid="project.classpath">
</pathconvert>
<!-- 创建目录结构 -->
<target name="init" depends="clear" description="创建初始化目录结构">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
</target>
<!-- javac编译任务 -->
<target name="compile" depends="init" description="编译java文件为javac文件" >
<javac srcdir="src" destdir="${classes.dir}"
includeantruntime="false" nowarn="on"
source="1.7" target="1.7" deprecation="true" debug="true"
encoding="UTF-8" classpathref="project.classpath" >
<compilerarg line="-Xlint:unchecked" />
</javac>
</target>
<!-- war打包任务 -->
<target name="war" depends="compile" description="打包为adjustSolr.war文件">
<echo message="begin war..." />
<war destfile="${build.dir}/${ant.project.name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="${webRoot.dir}" />
<lib dir="${lib.dir}"/>
<classes dir="${classes.dir}"/>
</war>
</target>
<!--clean任务 -->
<target name ="clear">
<delete dir ="build"/>
</target >
</project >
将build文件下的war包放在tomcat6.5-jdk1.7或者其他tomcat下 部署即可:
本地访问连接:http://localhost:8082/adjustSolr/solrSearch.jsp
通过服务器tomcat管理界面发布: