Eclipse项目中的Maven:软件包javax.ws.rs不存在 [英] Maven in Eclipse project: package javax.ws.rs does not exist

查看:2178
本文介绍了Eclipse项目中的Maven:软件包javax.ws.rs不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中,当我转到myProject->右键单击-> Run As-> Maven构建时,控制台中出现多个错误,概述某些软件包不存在,例如:

In Eclipse, when I go to myProject -> right click -> Run As -> Maven build, I am getting multiple errors in the console outlining that certain packages does not exist, like:

javax.ws.rs does not exist
javax.ws.rs.core does not exist
javax.servlet does not exist
javax.servlet.http doest not exist 

尽管在我的pom.xml中,我提供了那些依赖项:

Although in my pom.xml, I have provided those dependencies:

<dependency>
   <groupId>javax.ws.rs</groupId>
   <artifactId>javax.ws.rs-api</artifactId>
   <version>2.0.1</version>
</dependency>
<dependency>
   <groupId>javax.ws.rs</groupId>
   <artifactId>javax.ws.rs</artifactId>
   <version>1.0</version>
</dependency>
etc

<dependencyManagement><dependecies>

标签(pom.xml中没有任何错误).

tags (don't have any errors in pom.xml).

我也确实在settings.xml文件中配置了代理设置,并且该文件已正确链接.

I do also have proxy settings configured in settings.xml file, and this file is properly linked.

我还将这些jar包含在本地的WebContent \ WEB-INF \ lib文件夹中,并添加到类路径中(我可以在tomcat上运行我的REST服务,错误包不存在"仅在我尝试时出现使用Maven构建".

I've also got these jars included locally to WebContent\WEB-INF\lib folder and added to the classpath (I can run my REST service on tomcat, the error "package does not exist" appears only when I am trying to use Maven build".

我需要生成和部署.war文件的原因.

The reason I need that I want to generate and deploy a .war file.

我该如何解决?是否有战争迫使Maven在本地库中查找?

How I can solve this? Is there a war to force Maven look in local libraries instead?

推荐答案

如果有:

<dependencyManagement>
    <dependencies>
        <dependency>
           <groupId>javax.ws.rs</groupId>
           <artifactId>javax.ws.rs-api</artifactId>
           <version>2.0.1</version>
        </dependency>
        <dependency>
           <groupId>javax.ws.rs</groupId>
           <artifactId>javax.ws.rs</artifactId>
           <version>1.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

然后您需要单独设置:

<dependencies>
    <dependency>
       <groupId>javax.ws.rs</groupId>
       <artifactId>javax.ws.rs-api</artifactId>
    </dependency>
    <dependency>
       <groupId>javax.ws.rs</groupId>
       <artifactId>javax.ws.rs</artifactId>
    </dependency>
</dependencies>

部分.

通常,您将在父pom.xml文件中定义dependencyManagement,然后在子pom.xml文件中使用第二个dependencies片段.这样可以确保您的所有模块都依赖于相同的一致工件.

Typically you would define dependencyManagement in a parent pom.xml file and then use the second dependencies fragment in child pom.xml files. This ensures that all your modules depend upon the same consistent artifacts.

这篇关于Eclipse项目中的Maven:软件包javax.ws.rs不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆