我已经更新到更新版本的hibernate3-maven-plugin。我在尝试使用下面提到的插件时遇到以下错误。
将不胜感激在解决这个问题上的任何指示。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>create sql schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<persistenceunit>${app.module}</persistenceunit>
<drop>false</drop>
<create>true</create>
<outputfilename>${app.sql}-create.sql</outputfilename>
<skip>${db.schema.gen.skip}</skip>
</componentProperties>
</configuration>
</execution>
<execution>
<id>drop sql schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<persistenceunit>${app.module}</persistenceunit>
<drop>true</drop>
<create>false</create>
<outputfilename>${app.sql}-drop.sql</outputfilename>
<skip>${db.schema.gen.skip}</skip>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (create sql schema) on project sample: There was an error creating the AntRun task. NullPointerException -> [Help 1]org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (create sql schema) on project framework: There was an error creating the AntRun task.发布于 2012-02-17 23:56:13
配置方式改为直接使用ant hibernate工具插件。因此,配置与ant插件的格式完全相同,不需要额外的taskDef。有关更多信息,请参阅hibernate ant工具参考文档:http://docs.jboss.org/tools/3.3.0.Final/en/hibernatetools/html_single/index.html#d0e4651。
对于具有jpa配置的hbm2ddl,您可以使用以下内容:
<plugin>
<!-- run "mvn hibernate3:hbm2ddl" to generate a schema -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<configuration>
<hibernatetool>
<jpaconfiguration persistenceunit="unitname" />
<hbm2ddl export="false" create="true"
update="true" format="true" outputfilename="schemaDiff.ddl" />
</hibernatetool>
</configuration>
</plugin>在失败的上,有一个“/antrun/build-main.xml”文件,用于配置hibernate工具。对于上面的示例,如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<taskdef classname="org.hibernate.tool.ant.EnversHibernateToolTask" name="hibernatetool"/>
<mkdir dir="/home/xxx/workspace/projectname/target/sql/hibernate3"/>
<hibernatetool destdir="/home/xxx/workspace/projectname/target/sql/hibernate3">
<jpaconfiguration persistenceunit="schemaDiff"/>
<hbm2ddl update="true" export="false" outputfilename="schemaDiff.ddl" format=
"true" create="true"/>
</hibernatetool>
</target>
</project>发布于 2012-03-02 12:18:18
我也遇到了同样的问题,最后通过遵循这个示例(http://www.celinio.net/techblog/?p=1125)并单独为插件指定hibernate dep解决了这个问题。这是因为在我的例子中,我有一个单独的域对象模块,它只使用JPA2 (没有特定的hibernate引用),所以我需要为DDL生成引入dep,而不用担心它们会影响这个模块的依赖项。
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>jpaconfiguration</implementation>
</component>
</components>
<hibernatetool>
<classpath>
<path location="${project.build.directory}/classes" />
<path location="${project.basedir}/src/main/resources/META-INF/" />
</classpath>
<jpaconfiguration persistenceunit="Configuration" />
<hbm2ddl create="true" export="false" drop="true"
outputfilename="configuration.sql" format="true" console="true" />
</hibernatetool>
</configuration>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.7.Final</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>发布于 2012-04-22 08:44:46
我让它的工作方式如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<hibernatetool destdir="${project.basedir}">
<classpath>
<path
location="${project.basedir}/src/main/resources/mappings/" />
</classpath>
<configuration
configurationfile="${project.basedir}/src/test/resources/hibernate.cfg.xml" />
<hbm2ddl create="true" export="false"
drop="true" outputfilename="schema.sql"
format="true" console="false" />
</hibernatetool>
</configuration>
</execution>
</executions>
基本的想法是使用目标' run‘,然后配置hibernatetool来运行你想要的导出器。因此,您可以通过在标记中添加更多导出器配置来一次运行多个导出器。有关更多信息,请查看此处http://docs.jboss.org/tools/2.0.0.GA/hibernatetools/en/html_single/index.html和http://mojo.codehaus.org/hibernate3-maven-plugin/examples/run-multiple-goals.html。我花了几个小时才弄明白。希望对大家有所帮助!
https://stackoverflow.com/questions/9276808
复制相似问题