【问题标题】:Maven missing artifacts but files are in place - EclipseMaven 缺少工件但文件已就位 - Eclipse
【发布时间】:2020-03-25 03:34:46
【问题描述】:

我在我的 maven 项目中的 eclipse(2020-03) 中遇到两个错误,

The container 'Maven Dependencies' references non existing library 'C:\Users\Shavindi\.m2\repository\javax\servlet\jsp\javax.servlet.jsp-api\4.0.1\javax.servlet.jsp-api-4.0.1.jar' ```

Missing artifact javax.servlet.jsp:javax.servlet.jsp-api:jar:4.0.1  pom.xml /ContactManager line 47 Maven Dependency Problem 

我已经关注了这个问题Maven2: Missing artifact but jars are in place 中的答案。但它没有用。

我的 javax.servlet.jsp-api:jar:4.0.1 文件已经到位,如下所示。

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.codejava.contact</groupId>
  <artifactId>ContactManager</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>13</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <spring.version>5.9.1.RELEASE</spring.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId> 
        <artifactId>spring-webmvc</artifactId> 
        <version>4.2.2.RELEASE</version> 
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId> 
        <artifactId>spring-orm</artifactId> 
        <version>4.2.2.RELEASE</version> 
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId> 
        <artifactId>javax.servlet-api</artifactId> 
        <version>4.0.1</version> 
    </dependency>
      <dependency>
        <groupId>javax.servlet.jsp</groupId> 
        <artifactId>javax.servlet.jsp-api</artifactId> 
        <version>4.0.1</version> 
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId> 
        <artifactId>jstl</artifactId> 
        <version>1.2</version> 
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.19</version>
    </dependency>
  </dependencies>
</project>

【问题讨论】:

  • 去掉javax.servlet.jsp-api,试试maven是否报错?
  • 这是你想要的 jsp-api mvnrepository.com/artifact/javax.servlet/jsp-api/2.0 吗?你好像用错了。
  • 你检查文件系统了吗? Eclipse 正在显示其项目视图,该视图可能与文件系统不同步。
  • @AnishB。删除 javax.servlet.jsp-api 时没有错误
  • @AnishB。我还没有专门写过程序。运行 Maven 测试时。它没有显示错误。

标签: java spring eclipse maven


【解决方案1】:

pom.xml 中删除不必要的javax.servlet.jsp-api 依赖项。

<dependency>
        <groupId>javax.servlet.jsp</groupId> 
        <artifactId>javax.servlet.jsp-api</artifactId> 
        <version>4.0.1</version> 
</dependency>

另外,请Project -&gt; Clean 检查错误是否仍然存在?如果是,则Right Click on project -&gt; Maven -&gt; Update Project -&gt; Select update of snapshot 并启用Project -&gt; Build automatically

此外,他们还移动了神器。如果以后再写代码,可以使用下面的依赖。

<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>2.3.1</version>
</dependency>

您的 pom.xml 不正确。所以,我也更新了你的 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.codejava.contact</groupId>
  <artifactId>ContactManager</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>13</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <spring.version>4.2.2.RELEASE</spring.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId> 
        <artifactId>spring-webmvc</artifactId> 
        <version>${spring.version}</version> 
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId> 
        <artifactId>spring-orm</artifactId> 
        <version>${spring.version}</version> 
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId> 
        <artifactId>javax.servlet-api</artifactId> 
        <version>4.0.1</version> 
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId> 
        <artifactId>jstl</artifactId> 
        <version>1.2</version> 
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.19</version>
    </dependency>
  </dependencies>
</project>

【讨论】:

    【解决方案2】:

    我注意到您的 POM.xml 的 javax.servlet.jsp 版本错误。尝试用以下最新版本替换它。

    <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.3</version>
        <scope>provided</scope>
    </dependency>
    

    如果在进行更改后问题没有得到解决,请按照下面提到的步骤操作,看看是否有帮助。

    • 右键单击您的 Spring MVC 项目,选择 Run As -> Maven install。观察输出控制台以查看安装进度。安装完成后,可以继续下一步
    • 右键单击您的 Spring MVC 项目,选择 Maven -> 更新项目。
    • 选择您的项目并单击确定。等到更新过程完成。
    • 错误依旧,然后做Project->Clean,然后确保你已经选择了我们的项目目录,然后按照Project->Build进行。

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 2019-07-20
      • 1970-01-01
      • 2014-01-04
      • 2013-07-12
      • 2013-06-09
      • 2011-10-13
      • 2015-05-08
      • 1970-01-01
      相关资源
      最近更新 更多