先下载:xdoclet-plugins-dist-1.0.4-bin
build.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project name="OA系统构建脚本" default="生成Hibernate配置文件" basedir=".">
<property name="src.dir" value="${basedir}/src"/>
<!-- 配置路径 指定xdoclet-plugins-dist-1.0.4-bin文件的路径 -->
<property name="xdoclet.home" value="E:SoftDownloadxdoclet-plugins-dist-1.0.4-binxdoclet-plugins-dist-1.0.4"/>
<!-- build classpath -->
<path id="xdoclet.task.classpath">
<fileset dir="${xdoclet.home}/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<taskdef
name="xdoclet"
classname="org.xdoclet.ant.XDocletTask"
classpathref="xdoclet.task.classpath"
/>
<target name="生成Hibernate配置文件">
<xdoclet>
<fileset dir="${src.dir}/com/oa/model">
<include name="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
destdir="${src.dir}"
version="3.0"
hbm2ddlauto="update"
jdbcurl="jdbc:mysql://localhost/oa2"
jdbcdriver="com.mysql.jdbc.Driver"
jdbcusername="root"
jdbcpassword="****"
dialect="org.hibernate.dialect.MySQLDialect"
showsql="true"
/>
</xdoclet>
</target>
<target name="生成hibernate映射文件">
<xdoclet>
<fileset dir="${src.dir}/com/oa/model">
<include name="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
version="3.0"
destdir="${src.dir}"
/>
</xdoclet>
</target>
</project>
java文件
package com.oa.model;
/**
*
* @author zudajun225
* @hibernate.class table="t_person"
*/
public class Person {
/**
* @hibernate.id
* generator-class="native"
*/
private int id;
/**
* @hibernate.property
*/
private String name;
/**
* @hibernate.property
*/
private String sex;
/**
* @hibernate.property
*/
private String address;
/**
* @hibernate.property
*/
private String duty;
/**
* @hibernate.property
*/
private String phone;
/**
* @hibernate.property
*/
private String description;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}