ArtifactDescriptorException:无法读取javax.servlet的工件描述符:servlet-api:jar:$ {as.default.javax.servlet.version}

时间:2015-10-17 09:17:22

标签: maven

我正在使用maven和我的多模块项目。我无法解决错误。

错误在

下面给出
Description Resource    Path    Location    Type
ArtifactDescriptorException: Failed to read artifact descriptor for javax.servlet:servlet-api:jar:${as.default.javax.servlet.version}: ArtifactResolutionException: Failure to transfer javax.servlet:servlet-api:pom:${as.default.javax.servlet.version} from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact javax.servlet:servlet-api:pom:${as.default.javax.servlet.version} from/to central (http://repo.maven.apache.org/maven2): Illegal character in path at index 63: http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/${as.default.javax.servlet.version}/servlet-api-${as.default.javax.servlet.version}.pom pom.xml /kern-web-proxy line 1  Maven Dependency Problem

我只是maven的初学者,所以任何帮助对我都有价值。 这里是pom.xml

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>kern</artifactId>
        <groupId>com.appamsoft.as</groupId>
        <version>0.1-SNAPSHOT</version>
    </parent>

    <groupId>com.appamsoft.as.kern</groupId>
    <artifactId>kern-web-proxy</artifactId>
    <!-- <version>0.1-SNAPSHOT</version> -->
    <packaging>war</packaging>

    <name>kern-web-proxy</name>
    <dependencies>
        <dependency>
            <groupId>com.appamsoft.as.kern</groupId>
            <artifactId>kern-core</artifactId>
            <version>0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${as.default.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>${as.default.javax.servlet.version}</version>
            <scope>provided</scope>

        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>${as.default.javax.servlet.jsp.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${as.default.slf4j.version}</version>
        </dependency>
        <!-- <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        -->
         <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${as.default.log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.2</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>${as.default.java.version}</source>
                    <target>${as.default.java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <wtpversion>2.0</wtpversion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</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>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

多模块maven项目的屏幕截图如下: enter image description 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.appamsoft</groupId>
    <artifactId>as</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>as</name>
    <modules>
        <module>tools</module>
        <module>kern</module>
    </modules>
    <properties>
        <as.default.java.version>1.7</as.default.java.version>
        <as.default.junit.version>4.8.2</as.default.junit.version>
        <as.default.slf4j.version>1.6.6</as.default.slf4j.version>
        <as.default.log4j.version>1.2.16</as.default.log4j.version>
        <as.default.javax.servlet.version>2.5</as.default.javax.servlet.version>
        <as.default.javax.servlet.jsp.version>2.1</as.default.javax.servlet.jsp.version>
        <as.default.springframework.version>4.0.3.RELEASE</as.default.springframework.version>
        <as.default.hibernate.version>3.5.0-Final</as.default.hibernate.version>
        <as.default.camel.version>2.9.4</as.default.camel.version>
        <as.default.activemq.version>5.6.0</as.default.activemq.version>
        <project.build.maven.compiler.plugin.version>2.3.2</project.build.maven.compiler.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${as.default.slf4j.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${as.default.slf4j.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${as.default.log4j.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${as.default.junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>${as.default.javax.servlet.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>${as.default.javax.servlet.jsp.version}</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

2 个答案:

答案 0 :(得分:0)

kern-web-proxy的父级部分应为:

<parent>
  <groupId>com.appamsoft</groupId>
  <artifactId>as</artifactId>
  <version>0.1-SNAPSHOT</version>
</parent> 

或者它无法解析属性。但是,您父母的坐标正在解析某些内容,很可能是旧版本,否则您将收到另一个错误(类似于&#34;不可解析的父级&#34;)。

假设父POM在kern-web-proxy之上的一个目录中可用。如果不是这种情况,则需要使用<relativePath>标记添加调整您的父部分:

<parent>
  <groupId>com.appamsoft</groupId>
  <artifactId>as</artifactId>
  <version>0.1-SNAPSHOT</version>
  <!-- This should point to your parent POM if is not located at '..' -->
  <relativePath>../..</relativePath> 
</parent> 

答案 1 :(得分:-1)

首先我查看了本地仓库(.m2),我在kern-web-proxy pom.xml中使用了jar的名称不匹配。因此,我将jar的名称和版本号与本地repo jar相匹配。然后我得到了这个错误的解决方案。