使用maven命令行进行反向hibernate reverse hbm code 代码生成

用了Eclipse的插件半天没搞明白怎么用,还非常慢,最后看到一外国友人写的直接用mvn生成反向代码的帖子https://community.jboss.org/message/801327#801327才成功,现在介绍一下

1. 先创建一个空白maven项目,这个项目你爱叫啥名都可以,反正只是拿来生成代码用的,用完就可以删掉了



2. 往pom.xml 里面添加plugin

<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.0.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
					<encoding>UTF-8</encoding>
					<optimise>true</optimise>
					<compilerArgument>-nowarn</compilerArgument>
				</configuration>
			</plugin>
			     <plugin>
				   <groupId>org.codehaus.mojo</groupId>
				   <artifactId>hibernate3-maven-plugin</artifactId>
				   <version>2.2</version>
					 <configuration>
					   <components>
						 <component>
						   <name>hbm2hbmxml</name>
						   <implementation>jdbcconfiguration</implementation>
						   <outputDirectory>target/generated-resources/hibernate3</outputDirectory>
						 </component>
						 <component>
						   <name>hbm2java</name>
						   <implementation>jdbcconfiguration</implementation>
						   <outputDirectory>target/generated-sources/hibernate3</outputDirectory>
						 </component>
					   </components>
					   <componentProperties>
						 <revengfile>src/main/resources/reveng.xml</revengfile>
						 <propertyfile>src/main/resources/hibernate.properties</propertyfile>
						 <packagename>com.whatever.domain</packagename>
						 <jdk5>true</jdk5>
						 <ejb3>false</ejb3>
					   </componentProperties>
					 </configuration>
					 <dependencies>
					   <dependency>
						 <groupId>cglib</groupId>
						 <artifactId>cglib-nodep</artifactId>
						 <version>2.2.2</version>
					   </dependency>
					   <dependency>
						  <groupId>mysql</groupId>
						  <artifactId>mysql-connector-java</artifactId>
						  <version>5.1.25</version>
						</dependency>
					 </dependencies>
				   </plugin>
		</plugins>
	</build>

注意那个 com.whatever.domain 换成你自己的域名

3. 往 src/main/resources 下添加 hibernate.properties

hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://xxxxxx:xxxxx/xxxxx
hibernate.connection.username=xxxxx
hibernate.connection.password=xxxxx
4. 往 src/main/resources 下添加 reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC
  "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
  <schema-selection match-schema="MATCHDB"/>
</hibernate-reverse-engineering>
这个 MATCHDB 就是你要反向的库名

5. 如果你要生成注解方式的 java文件,就运行 mvn hibernate3:hbm2java

如果你要生成 hbm.xml 配合 java 的形式就先把 pom 里面 <ejb3>false</ejb3> 弄成false 然后分别运行 mvn hibernate3:hbm2hbmxml 和 mvn hibernate3:hbm2java


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值