在工程目录下创建libs/hibernate/ ,放入
hibernate-tools-3.2.0.ga.jar
jtidy-4aug2000r7-dev.jar
build.properties
project.name=sw
project.version=1.0
basedir=.
build.dir =${basedir}/build
web.dir = ${basedir}/WebRoot
lib.dir = ${basedir}/libs
sql.dir = ${basedir}/sql
config.dir=${basedir}/config
main.dir = ${basedir}/src
test.dir = ${basedir}/test
classes.dir = ${build.dir}/main/classes
test.classes.dir = ${build.dir}/test/classes
web.inf.dir = ${web.dir}/WEB-INF
web.lib.dir = ${web.inf.dir}/lib
database.dir = ${build.dir}/database
database.file = ${database.dir}/data
database.alias = sw
database.port= 3306
build.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- ====================================================================== 2008-1-20 friends description zhengfuchun ====================================================================== --> <project name="sw" default="help"> <description> description </description> <property file="build.properties" /> <path id="classpath.compile"> <fileset dir="${web.lib.dir}"> <include name="*.jar" /> </fileset> </path> <path id="classpath.compile.test"> <fileset dir="${web.lib.dir}/"> <include name="*.jar" /> </fileset> <fileset dir="${lib.dir}/test"> <include name="*.jar" /> </fileset> <fileset dir="${lib.dir}/jetty"> <include name="*.jar" /> </fileset> <pathelement path="${classes.dir}" /> </path> <path id="classpath.junit.test"> <path refid="classpath.compile.test" /> <pathelement path="${test.classes.dir}" /> </path> <path id="classpath.hibernate"> <pathelement path="${classes.dir}" /> <fileset dir="${web.lib.dir}/"> <include name="*.jar" /> </fileset> <fileset dir="${lib.dir}/hibernate"> <include name="*.jar" /> </fileset> </path> <!-- ================================= target: compile ================================= --> <target name="compile" description="description"> <deltree dir="${classes.dir}" /> <mkdir dir="${classes.dir}" /> <javac srcdir="${main.dir}" memoryinitialsize="32m" memorymaximumsize="128m" verbose="true" encoding="UTF-8" destdir="${classes.dir}" source="1.6" fork="true" classpathref="classpath.compile" debug="on" /> <mkdir dir="${classes.dir}/META-INF"/> <copydir dest="${classes.dir}/META-INF" src="${main.dir}/META-INF" /> </target> <!-- ================================= target: compile-test ================================= --> <target name="compile-test" description="description"> <deltree dir="${test.classes.dir}" /> <mkdir dir="${test.classes.dir}" /> <javac srcdir="${test.dir}" fork="true" verbose="true" encoding="UTF-8" destdir="${test.classes.dir}" classpathref="classpath.compile.test" debug="on" /> </target> <!-- ================================= target: hibernate-dbexport ================================= --> <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath.hibernate" /> <!-- ================================= target: generate-db ================================= --> <target name="generate-db" depends="compile" description="description"> <deltree dir="${build.dir}/generated/sql" /> <mkdir dir="${build.dir}/generated/sql" /> <hibernatetool> <jpaconfiguration persistenceunit="ApplicationEntityManager" propertyfile="${web.inf.dir}/config/jdbc.properties" /> <classpath> <path location="${classes.dir}" /> </classpath> <hbm2ddl destdir="${build.dir}/generated/sql" outputfilename="mysql.ddl" delimiter=";" format="true" haltοnerrοr="true" drop="true" export="true" /> </hibernatetool> </target> <!-- ================================= target: junit-test ================================= --> <target name="junit-test" description="description"> <deltree dir="${build.dir}/junit" /> <mkdir dir="${build.dir}/junit" /> <junit printsummary="yes"> <!-- 需要的classpath --> <classpath refid="classpath.junit.test" /> <batchtest todir="${build.dir}/junit"> <!-- 单元测试文件为所有src目录下的*Test.java文件 --> <fileset dir="${test.src.dir}"> <include name="**/*Test.java" /> </fileset> <!-- 生成格式为xml,也可以用plain或者brief --> <!-- 为什么生成xml,是为了下一步做report用 --> <formatter type="xml" /> </batchtest> </junit> <!-- 对xml文件生成相应的html文件在reports目录下 --> <!-- 如果指定于web可访问的目录,就可以使整个项目组看到单元测试情况 --> <mkdir dir="${build.dir}/junit/reports" /> <junitreport todir="${build.dir}/junit/reports"> <fileset dir="${build.dir}/junit"> <include name="TEST-*.xml" /> </fileset> <!-- 带有框架,可以用noframes选不带框架 --> <report format="frames" todir="${build.dir}/junit/reports/html" /> </junitreport> </target> <!-- 输出api文档 --> <target name="doc" description="create api doc"> <deltree dir="${api.doc.dir}" /> <mkdir dir="${api.doc.dir}" /> <echo>generate api doc</echo> <javadoc destdir="${api.doc.dir}" encoding="UTF-8" classpathref="classpath.junit.test" author="true" version="true" use="true" access="private" source="1.6" verbose="true" windowtitle="MyApp_API"> <packageset dir="${src.dir}" defaultexcludes="yes"> <exclude name="com/junit/**" /> </packageset> <doctitle> MyApp.cn</doctitle> <bottom>All Rights Reserved.</bottom> </javadoc> </target> <!-- ================================= target: jar ================================= --> <target name="jar" depends="compile" description="generate jar for all java classes"> <deltree dir="${build.dir}/bin" /> <mkdir dir="${build.dir}/bin" /> <jar destfile="${build.dir}/bin/${project.name}-${project.version}.jar" basedir="${classes.dir}" whenempty="create" encoding="UTF-8" /> </target> <!-- ================================= target: war ================================= --> <target name="war" depends="jar" description="generate war"> <copydir dest="${build.dir}/web" src="${web.dir}" /> <copyfile dest="${build.dir}/web/WEB-INF/lib/${project.name}-${project.version}.jar" src="${build.dir}/bin/${project.name}-${project.version}.jar" /> <war destfile="${build.dir}/bin/${project.name}-${project.version}.war" encoding="UTF-8" basedir="${build.dir}/web" webxml="${build.dir}/web/WEB-INF/web.xml"> </war> </target> <!-- ================================= target: help ================================= --> <target name="help" description="display help message"> <echo>******************************************************</echo> <echo>compile --compile all java source </echo> <echo>compile-test --compile all java test source </echo> <echo>jar --package all classes to a jar file </echo> <echo>war --package all web resources to a war file</echo> <echo>doc --generate all java api doc </echo> <echo>generate-db --generate dababase </echo> <echo>junit-test --run junit test and generate test reports</echo> <echo>help --display help message</echo> <echo>******************************************************</echo> </target> </project>
启动mysql
执行ant
数据库将自动生成