hibernate 之 xdoclet构建文件

来源:互联网 发布:手机键盘输入记录软件 编辑:程序博客网 时间:2024/04/30 03:09

开发环境:eclipse3.0.1+JBossIDE-1.4.1-jre1.4-e31+jBOSS4.0.1

xdoclet的一个很大用途在于从java文件生成相应的配置文件,下面的步骤就是从pojo生成相应的映射文件

step 1)写一个POJO(本文的重点在于产生构建文件,这一部分会在另外的文章中说明)

  @hibernate.class table="表名"


 这一句不能少,否这xdoclet不会生成映射文件

 这一句不能少,否这xdoclet不会生成映射文件

step2)写一个构建文件

用于执行xdoclet任务,当然你可以直接将该任务包含在项目的构建文件中,在本例子单独将该任务分离出来

在本文的开发环境中,当生成一个j2ee项目的时候jboss ide会自动产生一个xdoclet-build.xml的文件,通过右键点击项目名称-->porperties-->xdoclet configurations-->add standard--〉standard Hibernate,出现一个界面用于修改构建文件的内容,当然你可以自己手写,不用界面工具,产生构建文件后,你可以右键点击项目名称-->run xdoclet,当然你也可以直接将该构建文件加入eclipse的ant环境中执行,下面是构建文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<project default="_xdoclet_generation_" name="XDoclet Generator">
<property file="xdoclet-build.properties"/>
<property name="eclipse.home" value="G:/eclipse"/>
<property name="xdoclet.basedir" value="${eclipse.home}/plugins/org.jboss.ide.eclipse.xdoclet.core_1.4.1"/>
<property name="jboss.net.version" value="4.0"/>
<path id="project.classpath"><pathelement location="web/WEB-INF/classes"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/ejb-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/jacc-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/jca-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/jms-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/jsp-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/jta-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/servlet-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.j2ee.core_1.4.1/lib/j2ee-1.4/sql-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.ws.core_1.4.1/lib/wsi-1.0/jaxr-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.ws.core_1.4.1/lib/wsi-1.0/jaxrpc-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.ws.core_1.4.1/lib/wsi-1.0/saaj-api.jar"/>
<pathelement location="${eclipse.home}/plugins/org.jboss.ide.eclipse.jdt.ws.core_1.4.1/lib/wsi-1.0/xml-api.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/urlrewrite-1.2.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/c3p0-0.8.4.5.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/cglib-full-2.0.1.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-beanutils.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-collections.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-digester.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-fileupload.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-lang.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-logging.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/commons-validator.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/dom4j-1.4.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/easymock.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/ehcache-0.7.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/hibernate2.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/hsqldb.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/jakarta-oro.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/jstl.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/jta.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/junit.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/log4j-1.2.8.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/odmg-3.0.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/oscache-2.0.1.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/sitemesh-2.0.2.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/spring.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/standard.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/struts.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/struts-el.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/strutstest-2.1.0.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/equinox/web/WEB-INF/lib/aopalliance.jar"/>
<pathelement location="I:/hibernate-2.1/lib/xml-apis.jar"/>
<pathelement location="I:/hibernate-2.1/lib/ant-optional-1.5.3.jar"/>
<pathelement location="I:/hibernate-2.1/lib/c3p0-0.8.4.5.jar"/>
<pathelement location="I:/hibernate-2.1/lib/cglib-full-2.0.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/commons-collections-2.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/commons-dbcp-1.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/commons-lang-1.0.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/commons-logging-1.0.3.jar"/>
<pathelement location="I:/hibernate-2.1/lib/commons-pool-1.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/concurrent-1.3.2.jar"/>
<pathelement location="I:/hibernate-2.1/lib/connector.jar"/>
<pathelement location="I:/hibernate-2.1/lib/dom4j-1.4.jar"/>
<pathelement location="I:/hibernate-2.1/lib/ehcache-0.7.jar"/>
<pathelement location="I:/hibernate-2.1/lib/hsqldb.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jaas.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jboss-cache.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jboss-common.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jboss-jmx.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jboss-system.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jcs-1.0-dev.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jdbc2_0-stdext.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jgroups-2.2.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/jta.jar"/>
<pathelement location="I:/hibernate-2.1/lib/junit-3.8.1.jar"/>
<pathelement location="I:/hibernate-2.1/lib/log4j-1.2.8.jar"/>
<pathelement location="I:/hibernate-2.1/lib/odmg-3.0.jar"/>
<pathelement location="I:/hibernate-2.1/lib/oscache-2.0.jar"/>
<pathelement location="I:/hibernate-2.1/lib/proxool-0.8.3.jar"/>
<pathelement location="I:/hibernate-2.1/lib/swarmcache-1.0rc2.jar"/>
<pathelement location="I:/hibernate-2.1/lib/xalan-2.4.0.jar"/>
<pathelement location="I:/hibernate-2.1/lib/xerces-2.4.0.jar"/>
<pathelement location="I:/hibernate-2.1/lib/ant-1.5.3.jar"/>
<pathelement location="I:/hibernate-2.1/hibernate2.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xjavadoc-1.1.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-apache-module-1.2.3.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-ejb-module-1.2.3.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-hibernate-module-1.2.3.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-spring-module-1.2.3.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-web-module-1.2.3.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-xdoclet-module-1.2.3.jar"/>
<pathelement location="C:/Documents and Settings/Administrator/桌面/appfuse/lib/xdoclet-1.2.3/lib/xdoclet-1.2.3.jar"/>
</path>
<path id="xdoclet.classpath">
<path refid="project.classpath"/>
<fileset dir="${xdoclet.basedir}">
<include name="*.jar"/>
<exclude name="xdoclet-module-jboss-net-*.jar"/>
</fileset>
<fileset dir="${xdoclet.basedir}">
<include name="xdoclet-module-jboss-net-${jboss.net.version}*.jar"/>
</fileset>
</path>
<target name="_xdoclet_generation_" depends="N10004"/>
<target name="N10004" description="hibernate">
<taskdef classpathref="xdoclet.classpath" classname="xdoclet.modules.hibernate.HibernateDocletTask" name="hibernatedoclet"/>
 <hibernatedoclet excludedTags="@version,@author,@todo,@see"  destDir="src"  addedTags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}" >

<fileset dir="src"  includes="org/appfuse/model/*.java" >

</fileset>
<hibernate Version="2.0" >

</hibernate>

</hibernatedoclet></target>
</project>

该构建文件是长了点,但其实很简单,你只需关注最后一点带颜色的部分,前面是jboss ide为构建文件把整个项目的classpath都写了进去,红色部分即定义的xdoclet任务,其中destDir="src",表示声称的映射文件的位置,注意映射文件是带类路径的,比如pojo 位于org.appfuse.model下,那么生成的映射文件即在src/org/appfuse/model下;<fileset dir="src"  includes="org/appfuse/model/*.java" >表示你想映射的pojo的位置,很奇怪的是我想这样写<fileset dir="src/org/appfuse/model"  includes="*.java" >,构建后没任何反应,难道src中不能有多级目录,我以前在ant中写编译任务时,就曾在src中写过多级目录,在这个任务中试了半天不行,不得已只有将子目录写在includes里面


原创粉丝点击