maven-antrun-plugin生成空的dll文件

时间:2015-04-14 10:33:05

标签: pom.xml maven-antrun-plugin hibernate3-maven-plugin

我想用maven生成schema 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>

hibernate配置文件

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

请问好吗?

1 个答案:

答案 0 :(得分:0)

我的第一个建议是你应该更好地使用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