无法解析 Maven 工件

Posted

技术标签:

【中文标题】无法解析 Maven 工件【英文标题】:Maven artifacts could not be resolved 【发布时间】:2012-01-02 10:51:43 【问题描述】:

我将 spring 和 jboss 存储库添加到我的 pom.xml 中,如下所示:

<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">
    <name>MyProject</name>
    <url>http://www.myproject.com</url>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myproject</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>   
    <dependencies>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.3-b02</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.3_01</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.0.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>3.0-alpha-1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>runtime</scope>
        </dependency>

        <!-- SPRING DEPENDENCIES -->
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring</artifactId>  
            <version>3.0.6.RELEASE</version>
        </dependency>

        <!-- HIBERNATE DEPENDENCIES -->
        <dependency>  
            <groupId>org.hibernate</groupId>  
            <artifactId>hibernate</artifactId>  
            <version>3.5.4-Final</version>
        </dependency>

        <!-- PRIMEFACES -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>3.0.M4</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>aristo</artifactId>
            <version>1.0.1</version>
        </dependency>

        <!-- OTHER DEPENDENCIES -->
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.5</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.authorize</groupId>
            <artifactId>java-anet-sdk</artifactId>
            <version>1.4.2</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.2.12</version>
        </dependency>
        <dependency>
            <groupId>com.ocpsoft</groupId>
            <artifactId>prettyfaces-jsf2</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <endorsed.dir>$project.build.directory/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <netbeans.hint.j2eeVersion>1.6</netbeans.hint.j2eeVersion>
        <netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
    </properties>

    <repositories>
        <repository>
            <id>jsf20</id>
            <name>Repository for library Library[jsf20]</name>
            <url>http://download.java.net/maven/2/</url>
            <layout>default</layout>
        </repository>
        <repository>  
            <id>prime-repo</id>  
            <name>PrimeFaces Maven Repository</name>  
            <url>http://repository.primefaces.org</url>  
            <layout>default</layout> 
        </repository>
        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>spring-release</id>
            <name>Spring Release Repository</name>
            <url>http://maven.springframework.org/release</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>$endorsed.dir</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>$endorsed.dir</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>$project.artifactId</finalName>
    </build>
    <!--pluginRepositories>
        <pluginRepository>
            <id>caucho</id>
            <name>Caucho</name>
            <url>http://caucho.com/m2</url>
        </pluginRepository>
    </pluginRepositories-->
</project>

但是当我构建时,我得到一个错误:

The following artifacts could not be resolved: org.springframework:spring:jar:3.0.6.RELEASE, org.hibernate:hibernate:jar:3.5.4-Final: Could not find artifact org.springframework:spring:jar:3.0.6.RELEASE in jsf20 (http://download.java.net/maven/2/) -> [Help 1]

就像 maven 只查看第一个存储库,而不是为 spring 和 hibernate 定义的那些。

更新: 在命令行中使用 -X 和 -e 选项运行,但据我所知不是很有用:http://pastebin.com/c7nPzBc2

【问题讨论】:

奇怪,因为 spring 在 maven Central 中可用。应该不需要专门的回购。另外,我建议只包括您实际使用的弹簧工件。您可能不会使用所有东西 【参考方案1】:

这个错误只是说在 java.net 存储库中找不到它,它应该继续检查其他错误,直到找到一个确实有它的错误。您应该可以放心地忽略它。

此外,您为 spring 列出的 url 似乎已死,当我尝试直接去那里时,它给了我错误 500。无论哪种方式,它都是不必要的,因为可以在 maven Central 中找到 spring 工件(至少通过您列为依赖项的 3.0.6)。


经过一番调查,我发现自 2.5.6 以来,spring 还没有发布过 spring 工件。您将需要单独指定每个工件。例如:

<dependency>  
  <groupId>org.springframework</groupId>  
  <artifactId>spring-beans</artifactId>  
  <version>3.0.6.RELEASE</version>
</dependency>
<dependency>  
  <groupId>org.springframework</groupId>  
  <artifactId>spring-jdbc</artifactId>  
  <version>3.0.6.RELEASE</version>
</dependency>
<dependency>  
  <groupId>org.springframework</groupId>  
  <artifactId>spring-context</artifactId>  
  <version>3.0.6.RELEASE</version>
</dependency>
...

【讨论】:

当我尝试在 Netbeans 中构建时收到该错误,并因此显示“构​​建失败”。 尝试从命令行构建相同的项目。并使用 -X 选项了解更多详细信息。可能是它尝试下一个 repo,得到错误 500 并退出。不过不确定...

以上是关于无法解析 Maven 工件的主要内容,如果未能解决你的问题,请参考以下文章

无法解析工件/缺少工件 (Eclipse)

无法解析配置 ':classpath' 的所有工件。无法解析 com.android.tools.build:gradle:3.5.3。显示错误

无法解析项目的依赖关系。找不到工件。

intellij Gradle 同步错误:“无法解析配置':classpath'的所有工件。”

无法解析配置“:classpath”的所有工件。无法解析 org.jetbrains.kotlin:kotlin-reflect:1.2.71

无法解析配置“:classpath”的所有工件。 > 无法解析 com.android.tools.build:gradle:4.1.0