选择显示字体大小

进化中hibernate3脚本

hibernate有一些相当方便的辅助工具: hbm2java,hbm2ddl, 数据库的逆向工程,mapping editor.

这些任务可以通过ant构建完成,hibernate提供了ant tasks及其构建脚本.由于hibernate从2到3进行了重大重构,且包重新做了组织,因此ant构建脚本也发生了巨大变化.在2中脚本样式为:


<?xml version=&quot;1.0&quot;?>
<project name=&quot;anto builder&quot;
         default=&quot;db&quot; basedir=&quot;.&quot;>

  <!-- set up properties containing important project directories -->
  <property name=&quot;source.root&quot; value=&quot;src&quot;/>
  <property name=&quot;class.root&quot; value=&quot;classes&quot;/>
  <property name=&quot;lib.dir&quot; value=&quot;lib&quot;/>
  <property name=&quot;data.dir&quot; value=&quot;data&quot;/>

  <!-- set up the class path for compilation and execution -->
  <path id=&quot;project.class.path&quot;>
      <!-- include our own classes, of course -->
      <pathelement location=&quot;${class.root}&quot; />
      <!-- include jars in the project library directory -->
      <fileset dir=&quot;${lib.dir}&quot;>
        <include name=&quot;*.jar&quot;/>
      </fileset>
  </path>

  <target name=&quot;db&quot; description=&quot;runs hsqldb database management ui
against the database file--use when application is not running&quot;>
      <java classname=&quot;org.hsqldb.util.databasemanager&quot;
            fork=&quot;yes&quot;>
         <classpath refid=&quot;project.class.path&quot;/>
         <arg value=&quot;-driver&quot;/>
         <arg value=&quot;org.hsqldb.jdbcdriver&quot;/>
         <arg value=&quot;-url&quot;/>
         <arg value=&quot;jdbc:hsqldb:${data.dir}/music&quot;/>
         <arg value=&quot;-user&quot;/>
         <arg value=&quot;sa&quot;/>
      </java>
  </target>

  <!-- teach ant how to use hibernate's code generation tool -->
  <taskdef name=&quot;hbm2java&quot;
           classname=&quot.net.sf.hibernate.tool.hbm2java.hbm2javatask&quot;
           classpathref=&quot;project.class.path&quot;/>

  <!-- generate the java code for all mapping files in our source tree -->
  <target name=&quot;codegen&quot;
          description=&quot;generate java source from the o/r mapping files&quot;>
    <hbm2java output=&quot;${source.root}&quot;>
      <fileset dir=&quot;${source.root}&quot;>
        <include name=&quot;**/*.hbm.xml&quot;/>
      </fileset>
    </hbm2java>
  </target>

  <!-- create our runtime subdirectories and copy resources into them -->
  <target name=&quot;prepare&quot; description=&quot;sets up build structures&quot;>
    <mkdir dir=&quot;${class.root}&quot;/>

    <!-- copy our property files and o/r mappings for use at runtime -->
    <copy todir=&quot;${class.root}&quot; >
      <fileset dir=&quot;${source.root}&quot; >
        <include name=&quot;**/*.properties&quot;/>
        <include name=&quot;**/*.hbm.xml&quot;/>
      </fileset>
    </copy>
  </target>

  <!-- compile the java source of the project -->
  <target name=&quot;compile&quot; depends=&quot;prepare&quot;
          description=&quot;compiles all java classes&quot;>
    <javac srcdir=&quot;${source.root}&quot;
           destdir=&quot;${class.root}&quot;
           debug=&quot;on&quot;
           optimize=&quot;off&quot;
           deprecation=&quot;on&quot;>
      <classpath refid=&quot;project.class.path&quot;/>
    </javac>
  </target>

  <!-- generate the schemas for all mapping files in our class tree -->
  <target name=&quot;schema&quot; depends=&quot;compile&quot;
          description=&quot;generate db schema from the o/r mapping files&quot;>

    <!-- teach ant how to use hibernate's schema generation tool -->
    <taskdef name=&quot;schemaexport&quot;
             classname=&quot.net.sf.hibernate.tool.hbm2ddl.schemaexporttask&quot;
             classpathref=&quot;project.class.path&quot;/>

    <schemaexport properties=&quot;${class.root}/hibernate.properties&quot;
                  quiet=&quot;no&quot; text=&quot;no&quot; drop=&quot;no&quot;>
      <fileset dir=&quot;${class.root}&quot;>
        <include name=&quot;**/*.hbm.xml&quot;/>
      </fileset>
    </schemaexport>
  </target>
</project>

在3中,构建脚本为:

<?xml version=&quot;1.0&quot; encoding=&quot;gbk&quot;?>
<project name=&quot;hibernate&quot; default=&quot;anthbm2java&quot; basedir=&quot;.&quot;>
<property name=&quot;src.dir&quot; value=&quot;./src&quot; />
<property name=&quot;class.dir&quot; value=&quot;./bin&quot; />
<property name=&quot;lib.dir&quot; value=&quot;d:/eclipse/plugins/org.hibernate.eclipse_3.0.0.alpha4/lib&quot; />
<path id=&quot;project.class.path&quot;>
  <fileset dir=&quot;${lib.dir}&quot;>
   <include name=&quot;*.jar&quot;/>
  </fileset>
  <pathelement location=&quot;${class.dir}&quot; />
</path>
<path id=&quot;tasks.classpath&quot;>
  <fileset dir=&quot;${lib.dir}&quot;>
   <include name=&quot;*.jar&quot;/>
  </fileset>
  <pathelement location=&quot;${class.dir}&quot; />
</path>

<target name=&quot;anthbm2java&quot;>
       <taskdef name=&quot;hibernatetool&quot;
  classname=&quot;org.hibernate.tool.ant.hibernatetooltask&quot;
  classpathref=&quot;tasks.classpath&quot;/>
       <hibernatetool destdir=&quot;${class.dir}&quot;>
        <configuration configurationfile=&quot;hibernate.cfg.xml&quot; >
           <fileset dir=&quot;${src.dir}&quot;>
             <include name=&quot;**/*.hbm.xml&quot; />
           </fileset>  
         </configuration>
         <hbm2ddl export=&quot;false&quot; console=&quot;false&quot; create=&quot;true&quot; update=&quot;false&quot; drop=&quot;false&quot; outputfilename=&quot;broad.sql&quot; delimeter=&quot;;&quot;/>  其中的delimeter属性在hibernate-tool 3 a5版本中不支持.
        <hbm2java generics=&quot;true&quot; ejb3=&quot;false&quot;/>
        <cfg2hbm/><hbm2doc/>
        <!--
        <cfg2cfgxml/>  这个任务在hibernate-tool 3 a5版本中不支持.
        -->  
       </hibernatetool>  
</target>
</project>
hibernate3构建脚本的变化
这个脚本在eclipse中检验过.

通过这个脚本,执行了很多hibernate辅助工具的功能,方便了开发.

关于这些内容的参考可见:

http://www.hibernate.org/hib_docs/tools/ant/  其中有些反向工程的介绍.


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons