0

I keep getting the javax.ws.rs error while my dependencies should be right. How do I fix this?

I am using the IntelliJ IDE and when I import it in my project it does recognise javax.ws.rs.*. It does not give any error there.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>


<dependencies>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.6.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.johnzon</groupId>
        <artifactId>johnzon-jaxrs</artifactId>
        <version>0.9.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-jaxrs</artifactId>
        <version>1.9.13</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.johnzon</groupId>
        <artifactId>johnzon-jaxrs</artifactId>
        <version>1.1.7</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.44</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.192</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.github.binout</groupId>
        <artifactId>jaxrs-unit-api</artifactId>
        <version>1.1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.github.binout</groupId>
        <artifactId>jaxrs-unit-resteasy</artifactId>
        <version>1.1.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>
Sinan Samet
  • 6,432
  • 12
  • 50
  • 93
  • Where/when do you get "Getting package javax.ws.rs does not exist" error? Can you navigate to classes from this package via Navigate | Class action? Also since you set language level to 1.8 I assume you are not using java 9 modules, right? – Andrey Aug 22 '18 at 11:13
  • Thank you for your comment. The problem was that my project was on OneDrive. – Sinan Samet Aug 22 '18 at 14:38

2 Answers2

1

Yes, your dependencies seem to be right.

Try to update Idea's Maven indices as described here. Go to Preferences and type into search box Repositories than find it under Maven section, select remote repo in the table and press update button.

You might run then into another problem, when it takes infinite time to update indices('processing indices' phase takes minutes at any case) - just use this answers to fix the issue. To give more memory you can use Help->Edit Custom VM Options and set xmx to something like 2g

Kostiantyn
  • 1,856
  • 11
  • 13
  • Can you try File -> Invalidate Caches / Restart... and press the Invalidate and Restart button? – Kostiantyn Aug 21 '18 at 23:35
  • Yes I also did that but didn't change anything. I'm pretty sure it should be a problem with my IDE though since the project is an existing and working one. – Sinan Samet Aug 21 '18 at 23:37
  • Did you try to build it outside of IDE? Maybe the problem is with your local maven repo? Locate the `.m2` directory in your home folder. Then go to .m2/repository/javax/ws/rs and delete its content. Re-import maven project in IDE after that – Kostiantyn Aug 21 '18 at 23:46
  • The project I have was on my OneDrive location. After putting it on my C:/ drive it immediately worked. Thank you for your time! – Sinan Samet Aug 21 '18 at 23:51
0

The problem was that my project was in my OneDrive location. This caused me a lot of trouble but as soon as I moved it to my local drive it solved all of the problems.

Sinan Samet
  • 6,432
  • 12
  • 50
  • 93