在“导入Maven项目”期间发生内部错误。显示java.lang.NullPointerException

问题描述 投票:0回答:3

我在eclipse中导入maven项目时遇到此错误。我尝试在here发布的解决方案,但没有解决问题。不确定pom是否真的罪魁祸首但只是添加下面的代码

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>abc</groupId>
    <artifactId>xyz</artifactId>
    <packaging>jar</packaging>
    <name>Selenium Test</name>

    <build>
        <finalName>selenium</finalName>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

    </build>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.25.0</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>
eclipse maven
3个回答
0
投票

项目“最终名称”或pom.xml中的其他声明可能存在拼写错误。您可以从工作区中删除项目,然后将其导回。这应该至少在控制台中显示一些错误。如果您重新绘制项目名称,则可能会收到此错误。不知何故,折射器不会更新引用。


0
投票

我有同样的错误,我将工件和版本中的所有变量替换为预期值,然后完美导入项目,然后我返回所有变量


0
投票

它只是意味着pom.xml有错误。这可能是简单的拼写错误或某些依赖性的问题。这是一个逐步的方法,可以解决您的问题。

第1步:备份现有的pom.xml。

第2步:创建一个新项目POM。您可以使用下面的原样

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>samplemaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Your dependencies goes here. -->
    </dependencies>

</project>

第3步:更改groupId,artifatId等(需要进行最小的更改)。

步骤4:从项目目录中删除.project,.classpath和.settings文件夹(如果您之前有这些文件)。

第5步:在eclipse中导入项目。您不应该在导入时发现任何问题。

步骤6:导入完成后,更改新的pom.xml以从旧的pom.xml引入其他配置(在步骤1中备份)。

不要替换新的pom.xml,因为它最有可能带回原始问题。在改装时要小心,不要再次重新引入问题。

© www.soinside.com 2019 - 2024. All rights reserved.