XDoclet使用:
下载http://xdoclet.codehaus.org/
Ant+XDoclet:
在工程里创建一个需要映射的对象
/**  
 * @author kristain  
 * @hibernate.class table="t_user"  
 */  
public class User {   
    /**  
     * @hibernate.id  
     * generator-class="native"  
     */  
    private int id;   
    /**  
     * @hibernate.property  
     */  
    private String username;   
    /**  
     * @hibernate.property  
     */  
    private String password;   
    public int getId() {   
        return id;   
    }   
    public void setId(int id) {   
        this.id = id;   
    }   
    public String getUsername() {   
        return username;   
    }   
    public void setUsername(String username) {   
        this.username = username;   
    }   
    public String getPassword() {   
        return password;   
    }   
    public void setPassword(String password) {   
        this.password = password;   
    }   
}  

建立build.xml

<?xml version="1.0" encoding="UTF-8"?>  
<project name="构建脚本" default="生成Hibernate配置脚本" basedir=".">  
    <property name="src.dir" value="${basedir}/src"/>  
    <property name="xdoclet.home" value="D:/commons/xdoclet-plugins-dist-1.0.4"/>  
       
    <!-- build classpath -->  
    <path >  
        <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/model">  
                <include name="**/*.java"/>  
            </fileset>  
        </xdoclet>  
        <component  
            classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"  
            destdir="${src.dir}"  
            version="3.0"  
            jdbcurl="jdbc:mysql://localhost/oa"  
            jdbcdriver="com.mysql.jdbc.Driver"  
            jdbcusername="root"  
            jdbcpassword="root"  
            dialect="org.hibernate.dialect.MySQLDialect"  
            showsql="true"  
         />  
    </target>  
       
    <target name="生成hibernate映射文件">  
        <xdoclet>  
            <fileset dir="${src.dir}/com/model">  
                <include name="**/*.java"/>  
            </fileset>  
            <component  
                classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"  
                version="3.0"  
                destdir="${src.dir}"  
             />  
        </xdoclet>  
    </target>  
</project> 

在myeclipse中使用ant控制台,添加build.xml,运行生成hibernate配置文件

相关文章:

  • 2021-09-04
  • 2022-02-02
  • 2021-10-08
  • 2021-05-15
  • 2022-01-13
  • 2022-01-19
  • 2021-11-11
  • 2021-09-02
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2021-12-07
  • 2022-12-23
  • 2021-09-10
  • 2021-10-13
相关资源
相似解决方案