XDoclet

  • 介绍
XDoclet是一个开源的代码生成引擎。它是面向属性编程的(Attribute-Oriented Programming)。意味着你可以通过给java资源文件中添加元素据(属性)从而实现增加更多的信息。这都是通过JavaDoc标记来完成的。 XDoclet会解析你的源文件,并且生成XML等描述性文件。这可以让你在面向组件开发中使用 持续集成。开发者只需要关注源文件即可。 官网地址:http://xdoclet.sourceforge.net/xdoclet/index.html
  • 环境依赖
必须确保JDK中lib目录下的tools.jar在classpath环境变量中,而且需要 Jakarta Ant 1.5或者更高版本。
  • 下载
下载地址:http://sourceforge.net/projects/xdoclet/ xdoclet-lib-1.2, includes all needed libraries xdoclet-bin-1.2, includes the documentation, all needed libraries and samples xdoclet-src-1.2, includes scripts and sources needed to build XDoclet (see below)
  • 步骤
  1. 安装XDoclet
  2. 在Java源文件中添加XDoclet提供的注解,例如:@hibernate.class
  3. 编写ant文件——build.xml
  4. 执行ant任务
  • 生成Hibernate配置文件的例子
下面是源代码文件: [codesyntax lang="java"]
/**
 * http://surenpi.com
 */
package org.suren.xdoclet.example;

/**
 * @author suren
 * @date 2015年9月11日 上午10:20:49
 * @hibernate.class
 * 		table="S_Student"
 */
public class Student
{
	/**
	 */
	private String id;
	private String name;

	/**
	 * @return the id
	 * @hibernate.id
	 * 		generator-class="uuid.hex"
	 */
	public String getId()
	{
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id)
	{
		this.id = id;
	}

	/**
	 * @return the name
	 * @hibernate.property
	 * 		column="s_name"
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name)
	{
		this.name = name;
	}
}
[/codesyntax] 下面是build.xml的内容,从结构上分三块——引用XDoclet的类、定义XDoclet任务、执行任务: [codesyntax lang="xml"]
<?xml version="1.0" encoding="utf-8"?>
<project name="suren xdoclet project" basedir=".">
	<property name="src.dir" value="${basedir}/src" />
	<property name="xdoclet.home" value="C:/Users/zhaoxj/Desktop/xdoclet-1.2.1" />
	
	<path id="suren.class.path">
		<fileset dir="${xdoclet.home}/lib">
			<include name="**/*.jar"/>
		</fileset>
	</path>
	
	<target name="init">
		<taskdef name="hibernatexdoclet"
			classname="xdoclet.modules.hibernate.HibernateDocletTask"
			classpathref="suren.class.path"/>
	</target>
	
	<target name="suren" depends="init">
		<hibernatexdoclet destdir="suren-gen-src"
			mergedir="debug"
			addedtags="@author XDoclet"
			verbose="true">
			<fileset dir="D:/Gboat-Toolkit-Suit/workspace/xdoclet/src">
				<include name="**/*.java"/>
			</fileset>
			
			<hibernate version="2.0" />
			
			<hibernatecfg jdbcUrl="jdbc:mysql://localhost/test"
				driver="com.mysql.jdbc.Driver"
				dialect="org.hibernate.dialect.MySQLDialect"
				userName="root"
				password="root" />
		</hibernatexdoclet>
	</target>
</project>
[/codesyntax]

转载于:https://my.oschina.net/surenpi/blog/816896

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值