簡體   English   中英

maven-antrun-plugin生成emty ddl文件

[英]maven-antrun-plugin generating emty ddl file

我想用Maven生成架構SQL腳本。

這是我的持久性文件:

<?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>

休眠配置文件

<?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中的插件

<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,但不幸的是空了!

有什么想法嗎?

我的第一個建議是,您最好使用hibernate3-maven-plugin而不是maven-antrun-plugin因為它包含了您需要的所有內容,並且比必須使用maven-antrun-plugin編寫的所有配置都更易於使用。 maven-antrun-plugin (有關hibernate3-maven-plugin更多信息,請參見此處 )。

然后,要解決您的問題,我認為您可以在本文和答案中找到解決問題的答案,因為似乎所有給定的要素都會使您使配置工作順利。

並且不要忘了在編譯階段之后(例如,在流程類階段)綁定hibernate3-maven-plugin的運行(請參閱生命周期參考 ),然后僅運行mvn process-classes

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM