• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Maven in Netbeans to add Jersey dependency

 
Ashley Bye
Ranch Hand
Posts: 132
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to set up a project in Netbeans using Maven (my first time using Maven) with a dependency on Jersey. I am having trouble getting Netbeans to find the correct package for WebResource. According to the documentation I am following to set up a connection to a server I need to use the following code to test the connection:



However, Netbeans tells me that it cannot find the symbol class WebResource and asking the IDE to fix imports does not import the package. Below is my POM, created automatically by Netbeans with the dependencies after JUnit added by me:



I got the dependencies from the Jersey documentation. Could someone please explain what I am doing wrong?
 
Ashley Bye
Ranch Hand
Posts: 132
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I have managed to fix those issues with the following POM:


Do I actually need those plugins or should it work without those?

But I now get the following error on build:

 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can get rid of everything, except jersey-container-servlet (if you're writing servlets) or jersey-client (if you're writing clients). Maven will automatically get all other necessary dependencies.

The problem is probably that you're using <scope>provided</scope>, but you're not using a GlassFish server. Remove the scope from these dependencies, and it should work.
 
Ashley Bye
Ranch Hand
Posts: 132
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephan, several hours of Googling provided no clue about that. I even missed it in the Maven docs! What would you say is the best resource to learn amount using Maven for dependency management?
 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of what I know about Maven is from the POM reference, experimenting, and Google-fu when I run into a problem. It also helps that almost everything I've done in Java lately has been a Maven project.

It may seem a bit boring, but I really recommend going through the entire POM reference page on Apache. You can experiment with it while you go through it. It shouldn't take longer than a few hours.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything with "com.sun.jersey" sounds wrong for JAX-RS 2.0 and Jersey 2.6. See https://jersey.java.net/documentation/latest/modules-and-dependencies.html for details on the dependencies.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my Jersey apps I use the following dependencies (yes a little old, but that version gives me the full request/response logging which seems to be missing from the more recent version):

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic