wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Using Maven in Netbeans to add Jersey dependency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Using Maven in Netbeans to add Jersey dependency" Watch "Using Maven in Netbeans to add Jersey dependency" New topic
Author

Using Maven in Netbeans to add Jersey dependency

Ashley Bye
Ranch Hand

Joined: Jan 30, 2013
Posts: 46

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?


"Twenty years from now you will be more disappointed by the things you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover." - Mark Twain
Ashley Bye
Ranch Hand

Joined: Jan 30, 2013
Posts: 46

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

Joined: Sep 20, 2010
Posts: 3647
    
  16

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

Joined: Jan 30, 2013
Posts: 46

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

Joined: Sep 20, 2010
Posts: 3647
    
  16

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
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
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.


Ping & DNS - my free Android networking tools app
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

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



JBoss In Action
 
GeeCON Prague 2014
 
subject: Using Maven in Netbeans to add Jersey dependency