【问题标题】:Maven throws nullpointer exceptionMaven 抛出空指针异常
【发布时间】:2014-04-15 16:55:39
【问题描述】:

早安,

我已经使用 maven 构建了一个项目。在整个项目中,我得出的结论是,必须为特定模块添加一个依赖项。我在它的 pom 文件中添加了这个依赖项,当我尝试使用 maven 重建项目时,抛出了一个空指针。

之前的 Pom 文件:

(子 pom:)

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
    </dependency>

</dependencies>

(主要的 pom:)

    <dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


        <dependency>
            <groupId>com.solveit.crm.core</groupId>
            <artifactId>crm-core</artifactId>
            <version>${project.version}</version>
        </dependency> //this dependency is for another module, it was
                        declared at the start of the project


    </dependencies>
</dependencyManagement>

Pom 文件现在(导致空指针):

(子 pom:)

<dependencies>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
    </dependency>

    <dependency>
        <groupId>com.solveit.crm.data</groupId>
        <artifactId>crm-data</artifactId>
    </dependency>

</dependencies>

(主要的 pom:)

<dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


        <dependency>
            <groupId>com.solveit.crm.core</groupId>
            <artifactId>crm-core</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.solveit.crm.data</groupId>
            <artifactId>crm-data</artifactId>
            <version>${project.version}</version>
        </dependency>

    </dependencies>
</dependencyManagement>

为什么maven会抛出空指针异常?我现在很困惑。

错误信息:

    [INFO] Scanning for projects...
[ERROR] Internal error: java.lang.NullPointerException -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.NullPointerEx
ception
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:167)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
356)
Caused by: java.lang.NullPointerException
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:270)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        ... 11 more
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorE
xception

在日食中我得到:

    [INFO] Scanning for projects...
[ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.solveit.crm.data:crm-data:1'}' and 'Vertex{label='com.solveit.crm.core:crm-core:1'}' introduces to cycle in the graph com.solveit.crm.core:crm-core:1 --> com.solveit.crm.data:crm-data:1 --> com.solveit.crm.core:crm-core:1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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/ProjectCycleException

谢谢

【问题讨论】:

  • 你能分享完整的错误吗?
  • 异常跟踪?或错误信息请
  • 这无济于事,除非您显示错误消息,这是重要的部分
  • 已编辑,谢谢。
  • 使用命令窗口而不是 Eclipse 在同一项目目录下尝试 maven clean install 命令。

标签: java eclipse maven


【解决方案1】:

你有一个依赖的循环引用。

您的 crm-core 项目的依赖项中似乎包含 crm-data,而 crm-data 项目的依赖项中包含 crm-core。

Maven 无法编译这种情况。

【讨论】:

  • 这种情况应该怎么处理?如何让两个模块相互依赖?
  • 您可以将公共类/资源移动到第三个独立模块,并使两个现有模块依赖于这个公共模块。
  • 据我说,你不能。也许您可以为您的项目考虑另一个概念。您可以使用 ssssteffff 建议的通用模块。
  • 嗯,好吧...谢谢你们,我下次会记住这一点。干杯
  • 我不认为 Maven 因 NullPointerException 崩溃是解释循环依赖的最佳方式。
猜你喜欢
  • 1970-01-01
  • 2020-11-22
  • 2020-08-10
  • 2013-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多