Xdoclet结合Ant使用
2013-09-28 11:54
417 查看
XDoclet可以通过你在java源代码中的一些特殊的注释信息,自动为你生成配置文件、源代码等等,例如web、ejb的部署描述文件、为你生成struts的struts-config.xml配置文件、javascript校验等。
XDoclet is an open source code generation engine. It enables Attribute-Oriented Programming for java. In short, this means that you can add more significance to your code by adding meta data (attributes) to your java sources. This is done in special JavaDoc tags. This use of JavaDoc tags for attributes formed the original ideas for Java 5 Annotations.
XDoclet2 is the next generation of this technology. Based on Generama, it uses standard template engines such as Velocity and Freemarker for generation of text-oriented output, and Jelly for XML output. The function of XDoclet is to seed the generation contexts for these template engines.
创建build.xml配置文件:
<?xml version="1.0" encoding="GBK"?>
<projectname="系统构建脚本"default="生成Hibernate配置文件"basedir=".">
<propertyname="src.dir"value="${basedir}/src"/>
<propertyname="xdoclet.home"value="F:/Java/xdoclet-plugins-dist-1.0.4"/>
<!-- Build classpath -->
<pathid="xdoclet.task.classpath">
<filesetdir="${xdoclet.home}/lib">
<includename="**/*.jar"/>
</fileset>
<!--
<fileset dir="${xdoclet.home}/plugins">
<include name="**/*.jar"/>
</fileset>
-->
</path>
<taskdef
name="xdoclet"
classname="org.xdoclet.ant.XDocletTask"
classpathref="xdoclet.task.classpath"
/>
<targetname="生成Hibernate配置文件">
<xdoclet>
<filesetdir="${src.dir}/com/sjg/oa/model">
<includename="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
destdir="${src.dir}"
version="3.0"
hbm2ddlauto="update"
jdbcurl="jdbc:mysql://127.0.0.1/oa"
jdbcdriver="com.mysql.jdbc.Driver"
jdbcusername="root"
jdbcpassword="123456"
dialect="org.hibernate.dialect.MySQLDialect"
showsql="true"
/>
</xdoclet>
</target>
<targetname="生成hibernate映射文件">
<xdoclet>
<filesetdir="${src.dir}/com/sjg/oa/model">
<includename="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
version="3.0"
destdir="${src.dir}"
/>
</xdoclet>
</target>
</project>
User.java文件:(注释产生配置)
package com.sjg.oa.model;
/**
*
* @author SJG
* @hibernate.class table="t_user"
*/
publicclass User {
/**
* @hibernate.id
* generator-class="native"
*/
privateintid;
/**
* @hibernate.property
*
*/
private String username;
/**
* @hibernate.property
*
*/
private String password;
publicint getId() {
returnid;
}
publicvoid setId(int id) {
this.id = id;
}
public String getUsername() {
returnusername;
}
publicvoid setUsername(String username) {
this.username = username;
}
public String getPassword() {
returnpassword;
}
publicvoid setPassword(String password) {
this.password = password;
}
}
执行这两步,可以产生文件:
![](http://blog.51cto.com/attachment/201309/115231495.png)
成功结果:
User.hbm.xml文件
![](http://blog.51cto.com/attachment/201309/115307981.png)
Hibernate.cfg.xml配置文件
![](http://blog.51cto.com/attachment/201309/115403575.png)
XDoclet is an open source code generation engine. It enables Attribute-Oriented Programming for java. In short, this means that you can add more significance to your code by adding meta data (attributes) to your java sources. This is done in special JavaDoc tags. This use of JavaDoc tags for attributes formed the original ideas for Java 5 Annotations.
XDoclet2 is the next generation of this technology. Based on Generama, it uses standard template engines such as Velocity and Freemarker for generation of text-oriented output, and Jelly for XML output. The function of XDoclet is to seed the generation contexts for these template engines.
创建build.xml配置文件:
<?xml version="1.0" encoding="GBK"?>
<projectname="系统构建脚本"default="生成Hibernate配置文件"basedir=".">
<propertyname="src.dir"value="${basedir}/src"/>
<propertyname="xdoclet.home"value="F:/Java/xdoclet-plugins-dist-1.0.4"/>
<!-- Build classpath -->
<pathid="xdoclet.task.classpath">
<filesetdir="${xdoclet.home}/lib">
<includename="**/*.jar"/>
</fileset>
<!--
<fileset dir="${xdoclet.home}/plugins">
<include name="**/*.jar"/>
</fileset>
-->
</path>
<taskdef
name="xdoclet"
classname="org.xdoclet.ant.XDocletTask"
classpathref="xdoclet.task.classpath"
/>
<targetname="生成Hibernate配置文件">
<xdoclet>
<filesetdir="${src.dir}/com/sjg/oa/model">
<includename="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
destdir="${src.dir}"
version="3.0"
hbm2ddlauto="update"
jdbcurl="jdbc:mysql://127.0.0.1/oa"
jdbcdriver="com.mysql.jdbc.Driver"
jdbcusername="root"
jdbcpassword="123456"
dialect="org.hibernate.dialect.MySQLDialect"
showsql="true"
/>
</xdoclet>
</target>
<targetname="生成hibernate映射文件">
<xdoclet>
<filesetdir="${src.dir}/com/sjg/oa/model">
<includename="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
version="3.0"
destdir="${src.dir}"
/>
</xdoclet>
</target>
</project>
User.java文件:(注释产生配置)
package com.sjg.oa.model;
/**
*
* @author SJG
* @hibernate.class table="t_user"
*/
publicclass User {
/**
* @hibernate.id
* generator-class="native"
*/
privateintid;
/**
* @hibernate.property
*
*/
private String username;
/**
* @hibernate.property
*
*/
private String password;
publicint getId() {
returnid;
}
publicvoid setId(int id) {
this.id = id;
}
public String getUsername() {
returnusername;
}
publicvoid setUsername(String username) {
this.username = username;
}
public String getPassword() {
returnpassword;
}
publicvoid setPassword(String password) {
this.password = password;
}
}
执行这两步,可以产生文件:
![](http://blog.51cto.com/attachment/201309/115231495.png)
成功结果:
User.hbm.xml文件
![](http://blog.51cto.com/attachment/201309/115307981.png)
Hibernate.cfg.xml配置文件
![](http://blog.51cto.com/attachment/201309/115403575.png)
相关文章推荐
- xdoclet与Ant结合使用-简单例子
- 结合使用Hibernate和XDoclet
- Jibx 结合 ant使用的一些心得
- intellij idea包依赖 ivy 和ant结合使用
- ant结合iconfont使用
- About EJB 03 Xdoclet & ANT 组合使用中关于build.xml的设置
- eclipse及ant的结合使用【转载】
- ANT的使用(结合JUNIT、SVN)
- 使用Xdoclet和Ant构建Hibernate映射和配置文件
- 使用svnant结合svn进行项目构建
- 使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法
- Mybatis中使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件 推荐
- Mybatis中使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件
- 使用Xdoclet和Ant构建Hibernate映射和配置文件
- 使用Raven取代Ant来Build Java项目
- Xcode 和github结合使用
- http://sourceforge.net/projects/easymock/ ant结合junit进行软件自动测试
- Eclipse jetty和plugin 的结合使用
- TabLayout,ViewPager,Fragment结合使用
- tensorflow与kubernetes/docker结合使用实践