compilation error, package javax.ws.rs does not exist, dependencies not resolved from maven

I had mentioned the dependency libraries in the pom file, also the library system path exists also, but during the compilation using maven clean install -e -X, it throws error saying the package does not exists.

**[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[4,19] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:4: package javax.ws.rs does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[5,19] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:5: package javax.ws.rs does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[6,19] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:6: package javax.ws.rs does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[8,1] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:8: package javax.ws.rs.core does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[21,2] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:21: cannot find symbol
symbol: class Path**

POM file

<project xmlns="" xmlns:xsi="" xsi:schemaLocation=" "> <modelVersion>4.0.0</modelVersion> <groupId>RestfulService</groupId> <artifactId>RestfulService</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <sourceDirectory>${basedir}/src</sourceDirectory> <outputDirectory>${basedir}/build/classes</outputDirectory> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies> <dependency> <groupId>jersey-server</groupId> <artifactId>jersey-server</artifactId> <version>1.4</version> <scope>compile</scope> <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath> </dependency>
<dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs</artifactId> <version>1.4</version> <scope>system</scope> <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
</dependency>
</dependencies>
</dependencyManagement>
</project>

10 Answers

You need to include the Java EE dependencies in your POM, with a provided scope (aka, the files will eventually be provided by the application server, but in the meantime I need them for compilation).

<dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>6.0</version> <scope>provided</scope>
</dependency>
5

I had this and more similar issues after system update, when NetBeans changed fonts, and GUI in general. I have resolved this issue by adding Java EE 6 API Library in NetBeans IDE by doing

myProject->Properties->Libraries->Add Library

1

The dependency that @Perception replied with is also needed but it was not enough for me as well. The following dependency was also needed:

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

Τhis fixed the problem for me!

1

I think this dependency is better

<dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>1.1.1</version>
</dependency>

The modern day answer will be as below :

 <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-common</artifactId> </dependency>
1

Jersey is published in java.net repository; just use this (or better edit your user settings.xml):

<repositories> <repository> <id>maven2-repository.java.net</id> <name>Java.net Repository for Maven</name> <url> <layout>default</layout> </repository>
</repositories>
<dependencies> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.8</version> </dependency>
</dependencies>

JSR311 (javax.ws.rs) will be downloaded automatically by maven as a jersey-core dependency.

0

I resolved the issue by adding the dependencies in between the <project> tags instead of in dependency management.

In my case it was IntelliJ 'make' that was not working, although mvn clean install worked fine. The way to resolve it is to remove the two erroneous "Modules" from the "project Structure"->Modules tab, the modules were: main and test. Somehow they got in there from 'create project from existing source'.

I came through this error, the solution for me was to have both of this dependencies:

<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope>
</dependency>
<dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0</version>
</dependency>

I resolved the issue the same approach as @BugsForBreakfast. But wanted to share that javax.ws.rs-api artifact is been moved now. One can use the dependency below:

<dependency> <groupId>jakarta.ws.rs</groupId> <artifactId>jakarta.ws.rs-api</artifactId> <version>3.1.0</version>
</dependency>

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like