繁体   English   中英

Maven 缺少工件但文件已就位 - Eclipse

[英]Maven missing artifacts but files are in place - Eclipse

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

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>

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 -> Clean检查错误是否仍然存在? 如果是,则Right Click on project -> Maven -> Update Project -> Select update of snapshot并启用Project -> 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>

我注意到你的 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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM