首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven-antrun-plugin生成emty ddl文件

maven-antrun-plugin生成emty ddl文件
EN

Stack Overflow用户
提问于 2015-04-14 18:33:05
回答 1查看 380关注 0票数 0

我想用maven生成模式sql脚本。

这是我的永久文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="mypersistance"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
            <property name="hibernate.archive.autodetection" value="class"></property>
        </properties>
        <description>Persistance descriptor</description>
        <class>test.sofiane.beans.Code</class>
    </persistence-unit>
</persistence>

hibernate配置文件

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="mySessionFactory">
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.default_schema">public</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
    </session-factory>
</hibernate-configuration>

pom中的插件

代码语言:javascript
复制
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <!-- Hibernatetool will generate everything before running tests -->
            <phase>compile</phase>
            <configuration>
                <target>
                    <echo message="Ant target, through maven-antrun-plugin, started" />
                    <property name="maven_compile_classpath" refid="maven.compile.classpath" />
                    <property name="maven_test_classpath" refid="maven.test.classpath" />
                    <path id="hibernatetool.path">
                        <pathelement path="${maven_compile_classpath}" />
                        <pathelement path="${maven_test_classpath}" />
                    </path>
                    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
                        classpathref="hibernatetool.path" />
                    <property name="generatedByHibernate.outputDirectory"
                        value="${project.build.directory}/generated/hibernatetool" />
                    <mkdir dir="${generatedByHibernate.outputDirectory}" />

                    <hibernatetool destdir="${generatedByHibernate.outputDirectory}">
                        <classpath>
                            <path location="${project.build.directory}/classes/test/sofiane/beans" />
                        </classpath>
                        <configuration
                            configurationfile="${project.build.directory}/classes/hibernate.cfg.xml" />
                        <hbm2ddl export="true" drop="true" create="true"
                            outputfilename="helloworld.ddl" format="true" />
                    </hibernatetool>

                    <echo message="Ant target, through maven-antrun-plugin, terminated" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

pom运行良好并生成helloworld.ddl,但不幸的是它是空的!

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2015-05-05 17:09:59

我的第一个建议是,您最好使用hibernate3-maven-plugin而不是maven-antrun-plugin,因为它包含了您需要的所有内容,并且比您必须使用maven-antrun-plugin编写的所有配置简单得多(有关hibernate3-maven-plugin的更多信息,请参见here )。

然后,为了解决您的问题,我认为您可以在this post and in the answer中找到问题的答案,因为似乎给出的所有元素都会使您的配置工作良好。

别忘了在编译阶段之后绑定hibernate3-maven-plugin的运行,例如在进程类阶段(参见Lifecycle Reference),然后运行mvn process-classes

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29625109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档