Maven:缺少工件 org.springframework:spring:jar:4.2.6
Posted
技术标签:
【中文标题】Maven:缺少工件 org.springframework:spring:jar:4.2.6【英文标题】:Maven: missing artifact org.springframework:spring:jar:4.2.6 【发布时间】:2016-09-13 13:07:44 【问题描述】:我在 SpringToolSuite 中有一个动态 Web 项目。 它被转换为一个 Maven 项目。
我遇到了问题:
遗漏的工件 org.springframework:spring.jar:4.2.6
我已经尝试清理、重建和运行该项目。 它给出:
读取文件时出错 C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6\spring-4.2.6.jar C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6\spring-4.2.6.jar (系统找不到指定的文件)
我不明白为什么在我使用 Maven 时它要求提供 jar 文件?
pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>HelloWeb</groupId>
<artifactId>HelloWeb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\src\main\java</sourceDirectory>
<scriptSourceDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\src\main\scripts</scriptSourceDirectory>
<testSourceDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\src\test\java</testSourceDirectory>
<outputDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\target\classes</outputDirectory>
<testOutputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\test-classes</testOutputDirectory>
<resources>
<resource>
<directory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\src\test\resources</directory>
</testResource>
</testResources>
<directory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target</directory>
<finalName>HelloWeb-0.0.1-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</execution>
</executions>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
</reporting>
</project>
我已经看到了这个post,但不知何故我无法解决我的问题。
当我执行时
mvn 全新安装
在我得到的项目根目录下:
>mvn clean install
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/$%7Bspring.version%7D/spring-framework-bom-$%7Bspring.version%7D.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact org.springframework:spring-framework-bom:pom:$spring.version in central (https://repo.maven.apache.org/maven2) @ line 29, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-context:jar is missing. @ line 40, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-core:jar is missing. @ line 44, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-web:jar is missing. @ line 48, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-webmvc:jar is missing. @ line 52, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-aspects:jar is missing. @ line 56, column 17
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project HelloWeb:HelloWeb:0.0.1-SNAPSHOT (C:\Users\jublikon\Development\Spring\Projects\HelloWeb\pom.xml) has 6 errors
[ERROR] Non-resolvable import POM: Could not find artifact org.springframework:spring-framework-bom:pom:$spring.version in central (https://repo.maven.apache.org/maven2) @ line 29, column 21 -> [Help 2]
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-context:jar is missing. @ line 40, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-core:jar is missing. @ line 44, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-web:jar is missing. @ line 48, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-webmvc:jar is missing. @ line 52, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-aspects:jar is missing. @ line 56, column 17
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
我还检查了我的代理设置。 eclipse 中的活动提供者设置为“本机”,我没有通过代理连接
目录中
~/.m2/settings.xml
main is org.apache.maven.cli.MavenCli from plexus.core
set maven.home default $user.home/m2
[plexus.core]
optionally $maven.home/lib/ext/*.jar
load $maven.home/lib/*.jar
load $maven.home/conf/logging
【问题讨论】:
没有spring.jar
,所以永远找不到。从 Spring 3.0 开始,只有单独的模块(spring-beans、spring-context 等)可用。
您可以使用mvn clean install -X
跟踪问题以获取详细信息。
【参考方案1】:
我很确定没有名为“弹簧”的神器
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId> <!-- *** spring doesn't *** exist -->
<version>4.2.6</version>
</dependency>
根据你需要的Spring组件,你基本上应该包括这些依赖:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
在我的 Spring 项目中,我通过 BOM(材料清单)包含 Spring 工件:
<properties>
<spring.version>4.2.6.RELEASE</spring.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>$spring.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<!-- more -->
</dependencies>
【讨论】:
由于某种原因,尽管我正在使用您的代码,但我又遇到了同样的问题。我已经更新了我的问题。你能看一下吗? @jublikon 有一些事情你可以尝试...首先:关闭eclipse
,打开命令行窗口,进入项目目录(与pom.xml
所在的位置相同)并执行@987654326 @。会发生什么?
@jublikon second:在 eclipse 和 maven 的 ~/.m2/settings.xml
中检查您的代理设置@
感谢您的回答。我已经检查了您的建议并更新了我之前的帖子。
@jublikon 你的pom.xml
有问题。请显示完整的pom.xml
...我会更新我的答案,请查看<properties>
【参考方案2】:
对我有用的是我删除了
/Users/username/.m2/repository/org/springframework/spring/
目录
然后在我的项目中运行mvn clean install
命令。
这样 Maven 下载了以前我无法识别的真实 .jar 文件。
【讨论】:
对我来说,删除/Users/username/.m2/repository/org/springframework
目录并按照您的后一个解决方案进行操作。【参考方案3】:
默认情况下,Maven 会将所需的依赖项下载到您的本地存储库,以便下次可以更快地访问它们。也许依赖项已损坏或从本地磁盘中删除?您是否检查过 C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6\spring-4.2.6.jar 确实存在并且是有效的 spring jar 文件?
【讨论】:
我看到有两个文件:spring-4.2.6.jar.lastUpdated 和 spring-4.2.6.pom.lastUpdated。 taht 'lastUpdated' 文件是有效的 jar 文件吗? 不,所以您的 Maven 没有获取所需的依赖项。尝试在您的项目上运行 mvn clean install 并检查它是否正在下载任何工件 - 如果没有,您应该会收到一个错误,说明问题出在哪里。或者看看@Ulrich 的答案,这很可能是你的问题 - 无效的依赖描述 我认为您遇到了 Eclipse 的怪事。删除 C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6 目录并在项目上运行 mvn clean install。这将强制 maven 下载真正的 jar,而不是说“我之前尝试过,但没有用”。【参考方案4】:对我有用的是我从 mvnrepository 下载了 jar 文件,我从构建路径添加了它们,然后我在 Maven 构建中进行了干净编译安装,然后验证项目,然后更新项目,错误就消失了。
【讨论】:
【参考方案5】:对于 spring 框架,我在 pom.xml 文件中使用了以下依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.2RELEASE</version>
<scope>test</scope>
</dependency>
但它给了我错误
缺少工件 org.springframework.boot:spring-boot-starter-test:jar:4.3.2.RELEASE
但是当我将版本更改为最新版本时,错误已消除。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
所以尝试使用最新版本。
【讨论】:
【参考方案6】:此问题是因为所需的 .jar 文件在 .m2 存储库中不可用。
右击项目->Maven ->project Update
。
如果您使用工作组织中提供的settings.xml
,则删除该settings.xml
并重复步骤1。
当您放置 settings.xml
时,它总是会尝试从组织存储库下载所需的 .jar
文件。
【讨论】:
以上是关于Maven:缺少工件 org.springframework:spring:jar:4.2.6的主要内容,如果未能解决你的问题,请参考以下文章
Maven:缺少工件 org.springframework:spring:jar:4.2.6
Maven:POM.xml 中缺少工件 com.sun:tools:jar:1.6.0 编译时异常 [重复]
Hudson 无法构建我的 Maven 2 项目,因为它说存储库中缺少工件? (他们不是)
使用 Eclipse / Maven 构建 Hadoop - 缺少工件 jdk.tools:jdk.tools:jar:1.6