java 由于依赖项和/或插件导致 pom.xml 文件错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43287937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pom.xml file error due to dependencies and/or plugins
提问by Rami
I seem to have a pom.xml file error with dependencies/plugins, I generated this pom.xml file by converting the project to Maven which then only generated this pom file. View the error codes below. The Java code itself does not contain errors according to Eclipse STS (Java Spring), all jar files required by imports in the java code have been imported.
我的依赖项/插件似乎有一个 pom.xml 文件错误,我通过将项目转换为 Maven 生成了这个 pom.xml 文件,然后只生成了这个 pom 文件。查看下面的错误代码。Java代码本身根据Eclipse STS(Java Spring)不包含错误,java代码中import需要的jar文件都已经导入了。
Console error print when running the Java program:
运行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 file shows errors in a Java spring project.
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>
There's also a big red X on line 1.
第 1 行还有一个红色的大 X。
Error log from above code @line 16 :'plugin'
上面代码@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)
Error of POM.XML file line 16
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
EDITED according to comment adding dependencies; result = remaining errors remain unresolved, no new errors.
根据添加依赖项的评论进行编辑;结果 = 剩余错误仍未解决,没有新错误。
<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>
回答by Sukma Wardana
You put in the wrong place for <dependency>
tag, it's must be inside on <dependencies>
tag and it's not inside <build>
tag but it should be like this
你把<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>
.....
回答by user3251882
Some steps which may help:
一些可能有帮助的步骤:
- In some instance , you will start seeing error as we tried force update , saying , failure to transfer X dependency from Y path , resolutions will not be reattempted , bla bla bla In such case quickly fix it by cd to .m2/repository folder and run following command :
- 在某些情况下,当我们尝试强制更新时,您将开始看到错误,说无法从 Y 路径传输 X 依赖项,将不会重新尝试解析,bla bla bla 在这种情况下,通过 cd 快速将其修复到 .m2/repository 文件夹和运行以下命令:
for /r %i in (*.lastUpdated) do del %i
for /r %i in (*.lastUpdated) do del %i
- Rt click your project -> Maven -> Update project -> Select Force update -> Click OK
- Under properties tag , add :
- Rt 单击您的项目 -> Maven -> 更新项目 -> 选择强制更新 -> 单击确定
- 在属性标签下,添加:
> <maven.compiler.source>1.8</maven.compiler.source> > <maven.compiler.target>1.8</maven.compiler.target>
> <maven.compiler.source>1.8</maven.compiler.source> > <maven.compiler.target>1.8</maven.compiler.target>
回答by Moni
It seems like you don't have the jar for commons-logging just add the dependency in you pom.xml file whatever version you are using
似乎您没有用于 commons-logging 的 jar,只需在 pom.xml 文件中添加依赖项,无论您使用的是什么版本
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
Just try to add java version if you are using Java 8 and try to set the java path as well.
如果您使用的是 Java 8,请尝试添加 java 版本并尝试设置 java 路径。
<source>1.8</source>
<target>1.8</target>