Maven 示例 - NullPointer 执行 hibernate3:hbm2ddl

Posted

技术标签:

【中文标题】Maven 示例 - NullPointer 执行 hibernate3:hbm2ddl【英文标题】:Maven by example - NullPointer executing hibernate3:hbm2ddl 【发布时间】:2014-06-09 20:03:38 【问题描述】:

我正在按照Maven by example 指南学习 Maven。

我正忙于完成第 7 章,这是一个包含 spring 和 hibernate 的简单多模块企业项目。本章的示例文件可以在 ch-multi-spring 目录下here 下载。

第 7.1 到 7.6 节讨论了每个模块的细节。在section 7 中,生成数据库并运行应用程序。正是在这一步,我收到以下错误:

> mvn hibernate3:hbm2ddl -X
<Some output left out>
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Multi-Spring Chapter Simple Parent Project ........ FAILURE [0.752s]
[INFO] Multi-Spring Chapter Simple Object Model .......... SKIPPED
[INFO] Multi-Spring Chapter Simple Weather API ........... SKIPPED
[INFO] Multi-Spring Chapter Simple Persistence API ....... SKIPPED
[INFO] Multi-Spring Chapter Simple Command Line Tool ..... SKIPPED
[INFO] Multi-Spring Chapter Simple Web Application ....... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.330s
[INFO] Finished at: Thu Apr 24 15:31:18 CEST 2014
[INFO] Final Memory: 9M/154M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project simple-parent: 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 (default-cli) on project simple-parent: There was an error creating the AntRun task.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: There was an error creating the AntRun task.
    at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:84)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: java.lang.NullPointerException
    at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.add(DefaultPlexusConfiguration.java:175)
    at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.addChild(DefaultPlexusConfiguration.java:151)
    at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.setHibernateConfiguration(PlexusConfigurationUtils.java:289)
    at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.parseHibernateTool(PlexusConfigurationUtils.java:67)
    at org.codehaus.mojo.hibernate3.AbstractHibernateToolMojo.getConfiguration(AbstractHibernateToolMojo.java:60)
    at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:76)
    ... 21 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

由于我仍在学习 Maven,并且不熟悉 Hibernate,所以我不知道问题可能是什么。我没有更改下载的示例文件中的任何内容。

【问题讨论】:

【参考方案1】:

我遇到了同样的错误。 我修改了hibernate3-maven-plugin插件的版本号:

<groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <!-- insted of 2.1 as documented inside the Maven by example guide -->
  <version>2.2</version>  
  ....  
</groupId>

这解决了这个问题。此外,我使用的是 JDK 1.8。在“mvn -v”输出下方:

Java version: 1.8.0_20, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_20\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"

【讨论】:

【参考方案2】:

我想出了答案。

以下是我的发现总结:

mvn hibernate3:hbm2ddl 命令应该从simple-webappsimple-command 文件夹运行。 (插件的规范应该存在于该模块的 POM 中。) 将hibernate3-maven-plugin版本提高到3.0会重新引入问题,我相信我看过一些帖子说配置格式已更改,但我没有进一步研究。 如果 JAVA_HOME 设置为 JDK1.7 而不是 1.6,mvn hibernate3:hbm2ddl 将报告如下所示的错误(找到此here 的解决方案)

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.1:hbm2ddl (default-cli) on project simple-command: Could not get ConfigurationTask.

【讨论】:

我遇到了第二个问题;我尝试将我的 pom 中的 JDK 设置为 1.6,但这没有任何区别。我终于意识到(呃)当我运行 maven 时,它使用的是 1.7,这就是问题的根源。

以上是关于Maven 示例 - NullPointer 执行 hibernate3:hbm2ddl的主要内容,如果未能解决你的问题,请参考以下文章

setAdapter() 上的 NullPointer 异常

UnitTesting Android TabActivity时获取Nullpointer异常

wicket,spring jpa存储库 - @Autowire上的nullpointer

nullpointer遍历xml

Butterknife 片段旋转给出 NullPointer

@WebFilter 和 FacesContext.getCurrentInstance() -> Nullpointer