Maven 与休眠工具

发布于 2024-11-10 09:43:30 字数 2375 浏览 4 评论 0原文

我正在尝试使用 Maven 生成我的类和 hibernate.cfg.xml。 好吧,我的项目中有一些类依赖于生成的 java 文件,所以我可能必须在项目清理时执行这个过程?我不知道如何配置它才能工作,所以这是一个问题。 嗯,我有一个没问题的database.properties 文件和我修改过的很多hbm.xml 文件。现在我想从 hbm.xml 文件和database.properties 文件生成hibernate.cfg.xml 和所有java 文件。 我当前的 Maven 条目如下所示:

<plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>hbm2java</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>hbm2java</goal>
                    </goals>
                    <configuration>
                        <components>
                            <component>
                                <name>hbm2java</name>
                                <implementation>configuration</implementation>
                                <outputDirectory>src/main/java</outputDirectory>
                            </component>
                        </components>
                        <componentProperties>
                            <jdk5>true</jdk5>
                            <ejb3>true</ejb3>
                            <propertyfile>src/main/resources/database.properties</propertyfile>
                        </componentProperties>
                    </configuration>
                </execution>
            </executions>
            <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>

有人能帮我解决这个问题吗?我真的不知道该怎么做才能让这件事发挥作用。

I am trying to generate my classes and the hibernate.cfg.xml with maven.
Well i have classes in my project which depend on the generated java files so i will probably have to execute this process on project cleaning or so? I don't know how to configure this to work, so this is one question.
Well i have a database.properties file which is ok and a lot of hbm.xml files which i have modified. Now i want to generate the hibernate.cfg.xml and all java files from the hbm.xml files and the database.properties file.
My current maven entry looks like this:

<plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>hbm2java</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>hbm2java</goal>
                    </goals>
                    <configuration>
                        <components>
                            <component>
                                <name>hbm2java</name>
                                <implementation>configuration</implementation>
                                <outputDirectory>src/main/java</outputDirectory>
                            </component>
                        </components>
                        <componentProperties>
                            <jdk5>true</jdk5>
                            <ejb3>true</ejb3>
                            <propertyfile>src/main/resources/database.properties</propertyfile>
                        </componentProperties>
                    </configuration>
                </execution>
            </executions>
            <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>

Could anyone help me with this? I really don't know what to do, to get this thing working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

允世 2024-11-17 09:43:30

我的解决方案是使用我自己编写的插件。
您可以在这里找到它: http://uploaded.to/file/j3j7b652

示例用法:

   <plugin>
        <groupId>com.blazebit</groupId>
        <artifactId>HibernateCfgBuilder</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <id>HibernateCfgBuilder</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>HibernateCfgBuilder</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <hbmXmlFilesDir>src/main/resources/com/company/model/</hbmXmlFilesDir>
            <configFile>target/classes/hibernate.cfg.xml</configFile>
            <packageName>com.company.model</packageName>
        </configuration>
    </plugin>

如果您有有任何问题,尽管问。配置属性均已记录。

Well my solution is using my selfwritten plugin.
Here you can find it: http://uploaded.to/file/j3j7b652

Sample usage:

   <plugin>
        <groupId>com.blazebit</groupId>
        <artifactId>HibernateCfgBuilder</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <id>HibernateCfgBuilder</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>HibernateCfgBuilder</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <hbmXmlFilesDir>src/main/resources/com/company/model/</hbmXmlFilesDir>
            <configFile>target/classes/hibernate.cfg.xml</configFile>
            <packageName>com.company.model</packageName>
        </configuration>
    </plugin>

If you have any questions, ask. The configuration properties are all documented.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文