Maven in Eclipse project: package javax.ws.rs does not exist

让人想犯罪 __ 提交于 2020-01-24 12:05:11

问题


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 

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

under

<dependencyManagement><dependecies>

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

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

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".

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

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


回答1:


If you have:

<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>

then you need to have a separate:

<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>

section.

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.



来源:https://stackoverflow.com/questions/40355477/maven-in-eclipse-project-package-javax-ws-rs-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!