java - 如何配置maven hbm2hbmxml和hbm2java在mvn clean install中依次运行

标签 java hibernate maven

我需要能够调用 mvn clean install 并让 maven 调用 hibernate3:hbm2hbmxml 从数据库生成映射文件,然后调用 hbm2java 获取 Java 文件,然后让 maven 编译那些新创建的 Java 文件。 有没有人这样做过?

谢谢

最佳答案

如果你想编译你的模型 java 文件(由 reveng 获得),你不需要运行 hbm2hbmxml。

插件配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <components>
                    <component>
                        <name>hbm2java</name>
                        <outputDirectory>src/main/java</outputDirectory>
                        <implementation>jdbcconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <revengfile>/src/main/resources/reveng/model.reveng.xml</revengfile>
                    <propertyfile>/src/main/resources/META-INF/hibernate.properties</propertyfile>
                    <jdk5>true</jdk5>
                    <ejb3>true</ejb3>
                </componentProperties>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.0.8</version>
                </dependency>
                <dependency>
                    <groupId>cglib</groupId>
                    <artifactId>cglib-nodep</artifactId>
                    <version>2.1_3</version>
                </dependency>
            </dependencies>             
        </plugin>
    </plugins>
</build>

hibernate 属性:

hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/YOUR_DB
hibernate.connection.username = yourUsrName
hibernate.connection.password= yourPwd
hibernate.default_schema = YOUR_DB

模型.reveng.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
    <table-filter match-name=".*" package="your.package.here" />
</hibernate-reverse-engineering>

你用:

mvn clean hibernate3:hbm2java compile

如果你想让它被触发:

mvn clean compile

在你的插件定义中添加“executions”标签

            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals><goal>hbm2java</goal></goals>
                </execution>
            </executions>

关于java - 如何配置maven hbm2hbmxml和hbm2java在mvn clean install中依次运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2083727/

相关文章:

java - Hibernate 延迟加载抛出 JsonMappingException

java - Netbeans 上的 PermGen 空间错误

maven - maven surfire argLine 是否覆盖 ./mvn/jvm.config?

java - 使用 JNI 从 native C++ 调用 Java 方法时出错(ACCESS_VIOLATION 错误)

java - 无法在 Windows 上启动方形空间开发服务器

java - 有什么方法可以预测 session 超时吗?

java - Spring Boot 中的 Maven 依赖问题

java - 使用不同参数多次运行相同的 Junit 测试

java - Spring 和 hibernate : can't delete entry

java - 组织.hibernate.InstantiationException : Cannot instantiate abstract class or interface