从 hibernate-maven-plugin 2.2 版切换到 3.0 版时出现 NullPointerException

Posted

技术标签:

【中文标题】从 hibernate-maven-plugin 2.2 版切换到 3.0 版时出现 NullPointerException【英文标题】:NullPointerException when switching from hibernate-maven-plugin version 2.2 to version 3.0 【发布时间】:2012-10-19 06:50:33 【问题描述】:

我正在更新我的 pom.xml 依赖项的版本,当我更改 hibernate3-maven-plugin 的版本时遇到了一个模糊的错误

<plugin>
    <!-- Run "mvn hibernate3:hbm2ddl" to generate schema -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.2</version>
</plugin>

<plugin>
    <!-- Run "mvn hibernate3:hbm2ddl" to generate schema -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>3.0</version>
</plugin>

使用 2.2 版本,一切都编译成功,并且

mvn hibernate3:hbm2ddl

从带注释的类中创建正确的模式。

当我再次运行 hbm2ddl 命令时,只更改版本会导致以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project myProject: There was an error creating the AntRun task. NullPointerException -> [Help 1]

完整的堆栈跟踪如下:

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project myProject: 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 myProject: There was an error creating the AntRun task.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    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:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
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:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.lang.NullPointerException
    at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.add(DefaultPlexusConfiguration.java:174)
    at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.addChild(DefaultPlexusConfiguration.java:150)
    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

如果我回到 2.2 版,一切正常。而且因为除了拥有最新的依赖项之外,我不打算出于任何特定原因进行升级,所以我暂时坚持使用 2.2。

希望有人能对此有所了解!

【问题讨论】:

【参考方案1】:

将插件更新为以下内容,并且可以正常工作:

<plugin>
    <!-- Run "mvn hibernate3:hbm2ddl" to generate schema -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>$hibernate3.maven.plugin.version</version>

    <configuration>
        <hibernatetool>
            <annotationconfiguration propertyfile="src/main/resources/$hibernate.properties" />
            <hbm2ddl update="true" create="true" export="false"
                     outputfilename="$hibernate.hbm2ddl.sqlfile" format="true"
                     console="true" />
        </hibernatetool>
    </configuration>
</plugin>

【讨论】:

以上是关于从 hibernate-maven-plugin 2.2 版切换到 3.0 版时出现 NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章

如何从其他面板从 JTextField 获取输入

从PRISM开始学WPFMVVMViewModel?

在 python 中,为啥从数组读取比从列表读取慢?

从图库中挑选或从相机捕获的高质量图像

从PRISM开始学WPFMVVMCommand?

从PRISM开始学WPFPrism?