mvn archetype:generate
-DarchetypeGroupId=org.codehaus.mojo.archetypes
-DarchetypeArtifactId=webapp-javaee6 -DgroupId=example
-DartifactId=jersey2-helloworld -DarchetypeVersion=1.5
-DinteractiveMode=false
<repositories>
<repository>
<id>snapshot-repository.java.net</id>
<name>Java.net Snapshot Repository for Maven</name>
<url>https://maven.java.net/content/repositories/snapshots/</url>
<layout>default</layout>
</repository>
</repositories>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m09</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.0-m05</version>
<scope>test</scope>
</dependency>
@Path("movies")
public class MoviesResource {
@GET
@Path("list")
public List<Movie> getMovies() {
List<Movie> movies = new ArrayList<Movie>();
movies.add(new Movie("Million Dollar Baby", "Hillary Swank"));
movies.add(new Movie("Toy Story", "Buzz Light Year"));
movies.add(new Movie("Hunger Games", "Jennifer Lawrence"));
return movies;
}
}
mvn package
asadmin deploy --force=true target/jersey2-helloworld.war
@Test
public void testGetMovies() {
System.out.println("getMovies");
Client client = ClientFactory.newClient();
List<Movie> movieList = client.target("http://localhost:8080/jersey2-helloworld/webresources/movies/list")
.request()
.get(new GenericType<List<Movie>>() {});
assertEquals(3, movieList.size());
}
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running example.MoviesResourceTest
getMovies
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.561 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
GlassFish 4 contains Jersey 2 as the JAX-RS implementation. If
you want to use Jersey 1.1 functionality, then href="http://blog.alutam.com/2012/06/26/writing-web-applications-that-can-run-with-jersey-1-x-as-well-as-jersey-2-0/">Martin's
blog provide more details on that. All JAX-RS 1.x
functionality will be supported using standard APIs anyway. This
workaround is only required if Jersey 1.x functionality needs to
be accessed.
The complete source code explained in this project can be href="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/File/536181782352701534846a24f6d0a9f0/totd182_jersey2_helloworld.zip">downloaded
from here.
Here are some pointers to follow
Provide feedback on Jersey 2 to href="http://java.net/projects/jersey/lists/users/archive">users@jersey.java.net
and JAX-RS specification to href="http://java.net/projects/jax-rs-spec/lists/users/archive">users@jax-rs-spec.java.net.
Hi Arun, there's a typo in step 2 "respositories".
Thanks Stephen, fixed!
This is what I've been looking for. Thank you so much for sharing it. Now I don't have to Google it up further as you've finally showed me the answer. I'm a newbiew at this stuff, you see.