由于依赖项和/或插件导致的pom.xml文件错误

时间:2017-04-07 22:25:18

标签: java xml spring maven pom.xml

我似乎有一个带有依赖项/插件的pom.xml文件错误,我通过将项目转换为Maven来生成这个pom.xml文件,后者只生成了这个pom文件。查看下面的错误代码。根据Eclipse STS(Java Spring),Java代码本身不包含错误,导入了java代码中所需的所有jar文件。

运行Java程序时出现控制台错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:190)
    at testingpushnotifications.Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

pom.xml文件显示Java spring项目中的错误。

<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>Spring-Android-Push-Notifications-FCM--master</groupId>
  <artifactId>Spring-Android-Push-Notifications-FCM--master</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
        <plugin>   <--- ERROR HERE
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source/>
          <target/>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

第1行还有一个大的红色X.

错误记录来自以上代码@line 16:'plugin'

Multiple annotations found at this line:
    - Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile 
     (execution: default-compile, phase: compile)
    - CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.5.1 or one of its 
     dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.5.1: 
     ArtifactResolutionException: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.5.1 from/to central 
     (https://repo.maven.apache.org/maven2): NullPointerException
    - Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile 
     (execution: default-testCompile, phase: test-compile)

POM.XML文件第16行的错误

CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.5.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.5.1: ArtifactResolutionException: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.5.1 from/to central (https://repo.maven.apache.org/maven2): NullPointerException    pom.xml /Spring-Android-Push-Notifications-FCM--master  line 16 Maven Project Build Lifecycle Mapping Problem

根据评论添加依赖关系进行编辑;结果=剩余的错误仍未解决,没有新的错误。

<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>Spring-Android-Push-Notifications-FCM--master</groupId>
  <artifactId>Spring-Android-Push-Notifications-FCM--master</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
        <source>1.8</source>
        <target>1.8</target>
         <dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version> 
</dependency>
        </configuration> 
      </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-compiler-plugin
                                    </artifactId>
                                    <versionRange>
                                        [3.5.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

3 个答案:

答案 0 :(得分:2)

您为<dependency>标记放错了地方,它必须位于<dependencies>标记内,而且它不在<build>标记内,但它应该是像这样

....
<version>0.0.1-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version> 
    </dependency>
</dependencies>

<build>
.....

答案 1 :(得分:0)

看起来你没有jar用于commons-logging只是在pom.xml文件中添加依赖项,无论你使用什么版本

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version> 
</dependency>

如果您使用的是Java 8,请尝试添加Java版本,并尝试设置java路径。

<source>1.8</source>
<target>1.8</target>

答案 2 :(得分:0)

一些可能有用的步骤:

  1. 在某些情况下,当我们尝试强制更新时,您将开始看到错误,例如,无法从Y路径转移X依赖项,将不会重新尝试解决方案,等等。   在这种情况下,可以通过cd将其快速修复到.m2 / repository文件夹并运行以下命令:

对于(* .lastUpdated)中的/ r%i做del%i

  1. 右键单击您的项目-> Maven->更新项目->选择强制更新->单击确定
  2. 在属性标签下,添加:
>  <maven.compiler.source>1.8</maven.compiler.source> 
> <maven.compiler.target>1.8</maven.compiler.target>