1.配置ant,需要xdoclet-plugins-1.0.3文件
2.User实体类(注解一定要写,否则运行没有效果)
package com.zhlk.oa.model; /** * @hibernate.class table="T_User" */ public class User { /** * @hibernate.id * generator-class="native" */ private Integer id; /** * @hibernate.property */ private String username; /** * @hibernate.property */ private String password; public Integer getId() { return id; } public void setId(Integer 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; } } 3.bulid.xml文件 <?xml version="1.0" encoding="GBK"?> <project name="OA【01】系统构建脚本" default="生成Hibernate配置文件" basedir="."> <property name="src.dir" value="${basedir}/src"/> //D:/xdoclet-plugins-1.0.3/xdoclet-plugins-1.0.3这里就是xdoclet-plugins-1.0.3文件文件的路径 <property name="xdoclet.home" value="D:/xdoclet-plugins-1.0.3/xdoclet-plugins-1.0.3"/> <!-- Build classpath --> <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/zhlk/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="root" dialect="org.hibernate.dialect.MySQLDialect" showsql="true" /> </xdoclet> </target> <target name="生成hibernate映射文件"> <xdoclet> <fileset dir="${src.dir}/com/zhlk/oa/model"> <include name="**/*.java"/> </fileset> <component classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin" version="3.0" destdir="${src.dir}" /> </xdoclet> </target> </project> 4.运行antBuildfile: E:\MyEclipse 11\oa\build.xml 生成hibernate映射文件: [xdoclet] Running org.xdoclet.plugin.hibernate.HibernateMappingPlugin [xdoclet] * Generate mapping for 'User' entity BUILD SUCCESSFUL Total time: 27 seconds