ant 安装完成后 MyEclipse.--.> window >show view >other >ant 在ant 下右键 add 文件build.xml
build.xml:
<?xml version="1.0" encoding="GB2312" ?>
<project name="oa系统构建脚本" default="生成Hibernate配置文件" basedir=".">
<!-- properies -->
<!-- 定义一些常量 -->
<property name="src.dir" value="${basedir}/src" />
<property name="xdoclet.home" value="D:/Program Files/xdoclet-plugins-1.0.3" />
<path id="xdoclet.task.classpath">
<fileset dir="${xdoclet.home}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${xdoclet.home}/plugins">
<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/bjsxt/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/oa"
jdbcdriver="com.mysql.jdbc.Driver"
jdbcusername="root"
jdbcpassword="5759107"
dialect="org.hibernate.dialect.MySQLDialect"
showsql="true" />
</xdoclet>
</target>
<target name="生成Hibernate映射文件">
<xdoclet>
<fileset dir="${src.dir}/com/bjsxt/oa/model">
<include name="**/*.java" />
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
version="3.0"
destdir="${src.dir}" />
</xdoclet>
</target>
</project>
同时com.bjsxt.oa.model下的实体类,要写相应的注释如:
package com.bjsxt.oa.model;
/**
*
*
* @author Administrator
*@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;
/*
*
* @hibernate.many-to-one
* column="pid"
*/
private Orgnization org; //在数据库没发生作用啊
public Orgnization getOrg() {
return org;
}
public void setOrg(Orgnization org) {
this.org = org;
}
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;
}
}