Writing a REST service using the jetty plugin?

Howdy folks!

I'm a newbie web dev (ie, I've got plenty java experience, mostly on low-latency apps but almost nothing on servlets etc) and I'm tasked with writing a REST API using jetty.
I found the IDEA jetty plugin and thought it nifty to use it instead of embedding the jetty server.
I've configured the jetty server in the app server tab in prefs and created a module with jersey JAX_RS. I've created a small app (the infamous 'hello world'), created an artifact and
created a run configuration. I've added the artifact to the configuration but when I try to access the rest service I get a 404. I've tried various variants of the url but to no avail.
Is this possible?
My understanding is that you should be able to use annotations exclusivly and forgo a web.xml. Is this correct?

I'm grateful for any help here.

4 comments

hard to help without seeing the project.

0

Well, then I must do better. Prepare for a deluge of screenshots!

Here is the source:

package se.phlogiston.ib;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

/**
*         Date: 2014-06-15
*         Time: 17:09
*/
@Path("/helloworld")
public class HelloWorld {
    // The Java method will process HTTP GET requests
    @GET
    // The Java method will produce content identified by the MIME Media type "text/plain"
    @Produces("text/plain")
    public String getClichedMessage() {
        // Return some cliched textual content
        return "Hello World!!!!";
    }

}


Modules:

Screen Shot 2014-06-15 at 17.19.54.png

Artifact:

Screen Shot 2014-06-15 at 21.18.15.png
Jersey lib:

Screen Shot 2014-06-15 at 17.20.41.png

Run configuration:

Screen Shot 2014-06-15 at 17.20.59.png

Deployment for the run conf:

Screen Shot 2014-06-15 at 17.21.15.png

Hopefully this is a step in the right direction?

Still grateful for any help!

cheers
0

you are missing web.xml, or annotated servlet.

Try this, https://github.com/jasonray/jersey-starterkit
It works fine.

0

Ok, I got it to work now. What was missing (apart from the entire web.xml :-)) was the stanza :

        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>se.phlogiston.ib</param-value>
        </init-param>

Once that got added it just worked, as hoped for.

Surfing around a bit I found the '@ApplicationPath' annotation that replaced the web.xml with :

@ApplicationPath("/")
public class Application extends ResourceConfig {

    public Application() {
        packages("se.phlogiston.ib");
    }
}


Far easier, IMHO.


Message was edited by: Erik Svensson added part about ApplicationPath

0

Please sign in to leave a comment.