Table of Contents
This chapter provides a quick introduction on how to get started building RESTful services using Jersey. The example described here uses the lightweight Grizzly HTTP server. At the end of this chapter you will see how to implement equivalent functionality as a JavaEE web application you can deploy on any servlet container supporting Servlet 2.5 and higher.
Jersey project is built using Apache Maven software project build and management tool. All modules produced as part of Jersey project build are pushed to the Central Maven Repository. Therefore it is very convenient to work with Jersey for any Maven-based project as all the released (non-SNAPSHOT) Jersey dependencies are readily available without a need to configure a special maven repository to consume the Jersey modules.
In case you want to depend on the latest SNAPSHOT versions of Jersey modules, the following repository configuration needs to be added to your Maven project pom:
<snapshotRepository> <id>ossrh</id> <name>Sonatype Nexus Snapshots</name> <url>https://jakarta.oss.sonatype.org/content/repositories/snapshots/</url> </snapshotRepository>
Since starting from a Maven project is the most convenient way for working with Jersey, let's now have a look at this approach. We will now create a new Jersey project that runs on top of a Grizzly container. We will use a Jersey-provided maven archetype. To create the project, execute the following Maven command in the directory where the new project should reside:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \ -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \ -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \ -DarchetypeVersion=2.35
Feel free to adjust the groupId
, package
and/or artifactId
of your new project. Alternatively, you can change it by updating the new project pom.xml once it gets generated.
Once the project generation from a Jersey maven archetype is successfully finished, you should see the new
simple-service
project directory created in your current location. The directory contains
a standard Maven project structure:
Project build and management configuration is described in the pom.xml located
in the project root directory.
|
Project sources are located under src/main/java . |
Project test sources are located under src/test/java . |
There are 2 classes in the project source directory in the com.example
package.
The Main
class is responsible for bootstrapping the Grizzly container as well as configuring
and deploying the project's JAX-RS application to the container. Another class in the same package
is MyResource
class, that contains implementation of a simple JAX-RS resource.
It looks like this:
package com.example; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; /** * Root resource (exposed at "myresource" path) */ @Path("myresource") public class MyResource { /** * Method handling HTTP GET requests. The returned object will be sent * to the client as "text/plain" media type. * * @return String that will be returned as a text/plain response. */ @GET @Produces(MediaType.TEXT_PLAIN) public String getIt() { return "Got it!"; } }
A JAX-RS resource is an annotated POJO that provides so-called resource methods that
are able to handle HTTP requests for URI paths that the resource is bound to. See
Chapter 3, JAX-RS Application, Resources and Sub-Resources for a complete guide to JAX-RS resources. In our case, the resource
exposes a single resource method that is able to handle HTTP GET
requests, is bound to
/myresource
URI path and can produce responses with response message content represented
in "text/plain"
media type. In this version, the resource returns the same
"Got it!"
response to all client requests.
The last piece of code that has been generated in this skeleton project is a MyResourceTest
unit test class that is located in the same com.example
package as the
MyResource
class, however, this unit test class is placed into the maven project test source
directory src/test/java
(certain code comments and JUnit imports have been excluded for brevity):
package com.example; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import org.glassfish.grizzly.http.server.HttpServer; ... public class MyResourceTest { private HttpServer server; private WebTarget target; @Before public void setUp() throws Exception { server = Main.startServer(); Client c = ClientBuilder.newClient(); target = c.target(Main.BASE_URI); } @After public void tearDown() throws Exception { server.stop(); } /** * Test to see that the message "Got it!" is sent in the response. */ @Test public void testGetIt() { String responseMsg = target.path("myresource").request().get(String.class); assertEquals("Got it!", responseMsg); } }
In this unit test, a Grizzly container is first started and server application is deployed in the
test setUp()
method by a static call to Main.startServer()
.
Next, JAX-RS client components are created in the same test set-up method. First a new JAX-RS client
instance c
is built and then a JAX-RS web target component pointing to the context root of our
application deployed at http://localhost:8080/myapp/
(a value of
Main.BASE_URI
constant) is stored into a target
field of the unit test class.
This field is then used in the actual unit test method (testGetIt()
).
In the testGetIt()
method a fluent JAX-RS Client API is used to connect to and send
a HTTP GET
request to the MyResource
JAX-RS resource class listening on
/myresource
URI. As part of the same fluent JAX-RS API method invocation chain, a response is
read as a Java String
type. On the second line in the test method, the response content string
returned from the server is compared with the expected phrase in the test assertion. To learn more about using
JAX-RS Client API, please see the Chapter 5, Client API chapter.
Now that we have seen the content of the project, let's try to test-run it. To do this, we need to invoke following command on the command line:
mvn clean test
This will compile the project and run the project unit tests. We should see a similar output that informs about a successful build once the build is finished:
Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 7.519 s [INFO] Finished at: 2021-01-29T08:16:04+01:00 [INFO] ------------------------------------------------------------------------
Now that we have verified that the project compiles and that the unit test passes, we can execute the application in a standalone mode. To do this, run the following maven command:
mvn exec:java
The application starts and you should soon see the following notification in your console:
May 26, 2013 8:08:45 PM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [localhost:8080] Jan 29, 2021 8:33:02 AM org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer] Started. Jersey app started with WADL available at http://localhost:8080/myapp/application.wadl Hit enter to stop it...
This informs you that the application has been started and it's WADL descriptor is available at
http://localhost:8080/myapp/application.wadl
URL. You can retrieve the WADL content by
executing a curl http://localhost:8080/myapp/application.wadl
command in your console
or by typing the WADL URL into your favorite browser. You should get back an XML document in describing
your deployed RESTful application in a WADL format. To learn more about working with WADL, check the
Chapter 18, WADL Support chapter.
The last thing we should try before concluding this section is to see if we can communicate with our
resource deployed at /myresource
path. We can again either type the resource URL
in the browser or we can use curl
:
$ curl http://localhost:8080/myapp/myresource Got it!
As we can see, the curl
command returned with the Got it!
message that
was sent by our resource. We can also ask curl
to provide more information about the response,
for example we can let it display all response headers by using the -i
switch:
curl -i http://localhost:8080/myapp/myresource HTTP/1.1 200 OK Content-Type: text/plain Content-Length: 7 Got it!
Here we see the whole content of the response message that our Jersey/JAX-RS application returned, including all
the HTTP headers. Notice the Content-Type: text/plain
header that was derived from the
value of @Produces annotation attached to the MyResource
class.
In case you want to see even more details about the communication between our curl
client
and our resource running on Jersey in a Grizzly I/O container, feel free to try other various options and switches
that curl
provides. For example, this last command will make curl
output
a lot of additional information about the whole communication:
$ curl -v http://localhost:8080/myapp/myresource * Trying 127.0.0.1:8080... * TCP_NODELAY set * Connected to localhost (127.0.0.1) port 8080 (#0) > GET /myapp/myresource HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length: 7 < * Connection #0 to host localhost left intact Got it!
To create a Web Application that can be packaged as WAR and deployed in a Servlet container follow a similar process to the one described in Section 1.1, “Creating a New Project from Maven Archetype”. In addition to the Grizzly-based archetype, Jersey provides also a Maven archetype for creating web application skeletons. To create the new web application skeleton project, execute the following Maven command in the directory where the new project should reside:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp \ -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \ -DgroupId=com.example -DartifactId=simple-service-webapp -Dpackage=com.example \ -DarchetypeVersion=2.35
As with the Grizzly based project, feel free to adjust the groupId
, package
and/or artifactId
of your new web application project. Alternatively, you can change it by updating
the new project pom.xml
once it gets generated.
Once the project generation from a Jersey maven archetype is successfully finished, you should see the new
simple-service-webapp
project directory created in your current location. The directory contains
a standard Maven project structure, similar to the simple-service
project content we have seen
earlier, except it is extended with an additional web application specific content:
Project build and management configuration is described in the pom.xml located
in the project root directory.
|
Project sources are located under src/main/java . |
Project resources are located under src/main/resources . |
Project web application files are located under src/main/webapp . |
The project contains the same MyResouce
JAX-RS resource class. It does not contain any unit tests
as well as it does not contain a Main
class that was used to setup Grizzly container in the
previous project. Instead, it contains the standard Java EE web application web.xml
deployment
descriptor under src/main/webapp/WEB-INF
.
The last component in the project is an index.jsp
page that serves as a client for the
MyResource
resource class that is packaged and deployed with the application.
To compile and package the application into a WAR, invoke the following maven command in your console:
mvn clean package
A successful build output will produce an output similar to the one below:
Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ simple-service-webapp --- [INFO] Packaging webapp [INFO] Assembling webapp [simple-service-webapp] in [.../simple-service-webapp/target/simple-service-webapp] [INFO] Processing war project [INFO] Copying webapp resources [.../simple-service-webapp/src/main/webapp] [INFO] Webapp assembled in [110 msecs] [INFO] Building war: .../simple-service-webapp/target/simple-service-webapp.war [INFO] WEB-INF/web.xml already added, skipping [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.520 s [INFO] Finished at: 2021-01-29T08:42:11+01:00 [INFO] ------------------------------------------------------------------------
Now you are ready to take the packaged WAR (located under ./target/simple-service-webapp.war
)
and deploy it to a Servlet container of your choice.
To deploy a Jersey application, you will need a Servlet container that supports Servlet 2.5 or later. For full set of advanced features (such as JAX-RS 2.0 Async Support) you will need a Servlet 3.0 or later compliant container.
To create a Web Application that can be either packaged as WAR and deployed in a Servlet container or that can be pushed and deployed on Heroku the process is very similar to the one described in Section 1.4, “Creating a JavaEE Web Application”. To create the new web application skeleton project, execute the following Maven command in the directory where the new project should reside:
mvn archetype:generate -DarchetypeArtifactId=jersey-heroku-webapp \ -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \ -DgroupId=com.example -DartifactId=simple-heroku-webapp -Dpackage=com.example \ -DarchetypeVersion=2.35
Adjust the groupId
, package
and/or artifactId
of your new web
application project to your needs or, alternatively, you can change it by updating the new project pom.xml
once it
gets generated.
Once the project generation from a Jersey maven archetype is successfully finished, you should see the new
simple-heroku-webapp
project directory created in your current location. The directory contains
a standard Maven project structure:
Project build and management configuration is described in the pom.xml located
in the project root directory.
|
Project sources are located under src/main/java . |
Project resources are located under src/main/resources . |
Project web application files are located under src/main/webapp . |
Project test-sources (based on JerseyTest) are located under src/test/java . |
Heroku system properties (OpenJDK version) are defined in system.properties . |
Lists of the process types in an application for Heroku is in Procfile . |
The project contains one JAX-RS resource class, MyResouce
, and one resource method which returns
simple text message. To make sure the resource is properly tested there is also a end-to-end test-case
in MyResourceTest
(the test is based on JerseyTest from our Chapter 28, Jersey Test Framework).
Similarly to simple-service-webapp
, the project contains the standard Java EE web application
web.xml
deployment descriptor under src/main/webapp/WEB-INF
since the goal is to
deploy the application in a Servlet container (the application will run in Jetty on Heroku).
To compile and package the application into a WAR, invoke the following maven command in your console:
mvn clean package
A successful build output will produce an output similar to the one below:
Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ simple-heroku-webapp --- [INFO] Packaging webapp [INFO] Assembling webapp [simple-heroku-webapp] in [.../simple-heroku-webapp/target/simple-heroku-webapp] [INFO] Processing war project [INFO] Copying webapp resources [.../simple-heroku-webapp/src/main/webapp] [INFO] Webapp assembled in [122 msecs] [INFO] Building war: .../simple-heroku-webapp/target/simple-heroku-webapp.war [INFO] WEB-INF/web.xml already added, skipping [INFO] [INFO] --- maven-dependency-plugin:2.8:copy-dependencies (copy-dependencies) @ simple-heroku-webapp --- [INFO] Copying jetty-util-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-util-9.4.28.v20200408.jar [INFO] Copying jersey-hk2-2.33.jar to .../simple-heroku-webapp/target/dependency/jersey-hk2-2.33.jar [INFO] Copying javassist-3.25.0-GA.jar to .../simple-heroku-webapp/target/dependency/javassist-3.25.0-GA.jar [INFO] Copying jakarta.inject-2.6.1.jar to .../simple-heroku-webapp/target/dependency/jakarta.inject-2.6.1.jar [INFO] Copying hk2-locator-2.6.1.jar to .../simple-heroku-webapp/target/dependency/hk2-locator-2.6.1.jar [INFO] Copying hk2-utils-2.6.1.jar to .../simple-heroku-webapp/target/dependency/hk2-utils-2.6.1.jar [INFO] Copying hk2-api-2.6.1.jar to .../simple-heroku-webapp/target/dependency/hk2-api-2.6.1.jar [INFO] Copying jetty-webapp-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-webapp-9.4.28.v20200408.jar [INFO] Copying jakarta.annotation-api-1.3.5.jar to .../simple-heroku-webapp/target/dependency/jakarta.annotation-api-1.3.5.jar [INFO] Copying jersey-server-2.33.jar to .../simple-heroku-webapp/target/dependency/jersey-server-2.33.jar [INFO] Copying jakarta.ws.rs-api-2.1.6.jar to .../simple-heroku-webapp/target/dependency/jakarta.ws.rs-api-2.1.6.jar [INFO] Copying osgi-resource-locator-1.0.3.jar to .../simple-heroku-webapp/target/dependency/osgi-resource-locator-1.0.3.jar [INFO] Copying aopalliance-repackaged-2.6.1.jar to .../simple-heroku-webapp/target/dependency/aopalliance-repackaged-2.6.1.jar [INFO] Copying jetty-servlet-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-servlet-9.4.28.v20200408.jar [INFO] Copying jetty-xml-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-xml-9.4.28.v20200408.jar [INFO] Copying jersey-container-servlet-2.33.jar to .../simple-heroku-webapp/target/dependency/jersey-container-servlet-2.33.jar [INFO] Copying jetty-io-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-io-9.4.28.v20200408.jar [INFO] Copying jetty-security-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-security-9.4.28.v20200408.jar [INFO] Copying jetty-server-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-server-9.4.28.v20200408.jar [INFO] Copying javax.servlet-3.0.0.v201112011016.jar to .../simple-heroku-webapp/target/dependency/javax.servlet-3.0.0.v201112011016.jar [INFO] Copying jersey-common-2.33.jar to .../simple-heroku-webapp/target/dependency/jersey-common-2.33.jar [INFO] Copying jakarta.validation-api-2.0.2.jar to .../simple-heroku-webapp/target/dependency/jakarta.validation-api-2.0.2.jar [INFO] Copying jersey-container-servlet-core-2.33.jar to .../simple-heroku-webapp/target/dependency/jersey-container-servlet-core-2.33.jar [INFO] Copying jersey-client-2.33.jar to .../simple-heroku-webapp/target/dependency/jersey-client-2.33.jar [INFO] Copying jetty-http-9.4.28.v20200408.jar to .../simple-heroku-webapp/target/dependency/jetty-http-9.4.28.v20200408.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12.009 s [INFO] Finished at: 2021-01-29T08:48:04+01:00 [INFO] ------------------------------------------------------------------------
Now that you know everything went as expected you are ready to:
./target/simple-service-webapp.war
) and deploy it to a
Servlet container of your choice, or
If you want to make some changes to your application you can run the application locally by simply running
mvn clean package jetty:run
(which starts the embedded Jetty server) or by
java -cp target/classes:target/dependency/* com.example.heroku.Main
(this is how Jetty is
started on Heroku).
We won't go into details how to create an account on Heroku and setup the Heroku
tools
on your machine. You can find a lot of information in this article: Getting Started with Java on Heroku.
Instead, we'll take a look at the steps needed after your environment is ready.
The first step is to create a Git repository from your project:
$ git init Initialized empty Git repository in /.../simple-heroku-webapp/.git/
Then, create a Heroku instance and add a remote reference to your Git repository:
$ heroku create Creating simple-heroku-webapp... done, stack is cedar http://simple-heroku-webapp.herokuapp.com/ | git@heroku.com:simple-heroku-webapp.git Git remote heroku added
The name of the instance is changed in the output to simple-heroku-webapp
. Your will be
named more like tranquil-basin-4744
.
Add and commit files to your Git repository:
$ git add src/ pom.xml Procfile system.properties
$ git commit -a -m "initial commit" [master (root-commit) e2b58e3] initial commit 7 files changed, 221 insertions(+) create mode 100644 Procfile create mode 100644 pom.xml create mode 100644 src/main/java/com/example/MyResource.java create mode 100644 src/main/java/com/example/heroku/Main.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/test/java/com/example/MyResourceTest.java create mode 100644 system.properties
Push changes to Heroku:
$ git push heroku master Counting objects: 21, done. Delta compression using up to 8 threads. Compressing objects: 100% (11/11), done. Writing objects: 100% (21/21), 3.73 KiB | 0 bytes/s, done. Total 21 (delta 0), reused 0 (delta 0) -----> Java app detected -----> Installing OpenJDK 1.8... done -----> Installing Maven 3.6.3... done -----> Installing settings.xml... done -----> executing /app/tmp/cache/.maven/bin/mvn -B -Duser.home=/tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd -Dmaven.repo.local=/app/tmp/cache/.m2/repository -s /app/tmp/cache/.m2/settings.xml -DskipTests=true clean install [INFO] Scanning for projects... [INFO] [INFO] ------------------ com.example:simple-heroku-webapp ------------------ [INFO] Building simple-heroku-webapp 1.0-SNAPSHOT [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ simple-heroku-webapp --- [INFO] Deleting /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ simple-heroku-webapp --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ simple-heroku-webapp --- [INFO] Compiling 2 source files to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ simple-heroku-webapp --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ simple-heroku-webapp --- [INFO] Compiling 1 source file to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ simple-heroku-webapp --- [INFO] Surefire report directory: /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.example.MyResourceTest Jan 29, 2021 9:13:20 AM org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory$GrizzlyTestContainer INFO: Creating GrizzlyTestContainer configured at the base URI http://localhost:9998/ Jan 29, 2021 9:13:20 AM org.glassfish.jersey.server.wadl.WadlFeature configure WARNING: JAXBContext implementation could not be found. WADL feature is disabled. Jan 29, 2021 9:13:21 AM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [localhost:9998] Jan 29, 2021 9:13:21 AM org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer] Started. Jan 29, 2021 9:13:21 AM org.glassfish.grizzly.http.server.NetworkListener shutdownNow INFO: Stopped listener bound to [localhost:9998] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.476 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ simple-heroku-webapp --- [INFO] Packaging webapp [INFO] Assembling webapp [simple-heroku-webapp] in [/tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/simple-heroku-webapp] [INFO] Processing war project [INFO] Copying webapp resources [/tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/src/main/webapp] [INFO] Webapp assembled in [115 msecs] [INFO] Building war: /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/simple-heroku-webapp.war [INFO] WEB-INF/web.xml already added, skipping [INFO] [INFO] --- maven-dependency-plugin:2.8:copy-dependencies (copy-dependencies) @ simple-heroku-webapp --- [INFO] Copying jetty-util-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-util-9.4.28.v20200408.jar [INFO] Copying jersey-hk2-2.33.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jersey-hk2-2.33.jar [INFO] Copying javassist-3.25.0-GA.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/javassist-3.25.0-GA.jar [INFO] Copying jakarta.inject-2.6.1.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jakarta.inject-2.6.1.jar [INFO] Copying hk2-locator-2.6.1.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/hk2-locator-2.6.1.jar [INFO] Copying hk2-utils-2.6.1.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/hk2-utils-2.6.1.jar [INFO] Copying hk2-api-2.6.1.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/hk2-api-2.6.1.jar [INFO] Copying jetty-webapp-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-webapp-9.4.28.v20200408.jar [INFO] Copying jakarta.annotation-api-1.3.5.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jakarta.annotation-api-1.3.5.jar [INFO] Copying jersey-server-2.33.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jersey-server-2.33.jar [INFO] Copying jakarta.ws.rs-api-2.1.6.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jakarta.ws.rs-api-2.1.6.jar [INFO] Copying osgi-resource-locator-1.0.3.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/osgi-resource-locator-1.0.3.jar [INFO] Copying aopalliance-repackaged-2.6.1.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/aopalliance-repackaged-2.6.1.jar [INFO] Copying jetty-servlet-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-servlet-9.4.28.v20200408.jar [INFO] Copying jetty-xml-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-xml-9.4.28.v20200408.jar [INFO] Copying jersey-container-servlet-2.33.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jersey-container-servlet-2.33.jar [INFO] Copying jetty-io-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-io-9.4.28.v20200408.jar [INFO] Copying jetty-security-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-security-9.4.28.v20200408.jar [INFO] Copying jetty-server-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-server-9.4.28.v20200408.jar [INFO] Copying javax.servlet-3.0.0.v201112011016.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/javax.servlet-3.0.0.v201112011016.jar [INFO] Copying jersey-common-2.33.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jersey-common-2.33.jar [INFO] Copying jakarta.validation-api-2.0.2.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jakarta.validation-api-2.0.2.jar [INFO] Copying jersey-container-servlet-core-2.33.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jersey-container-servlet-core-2.33.jar [INFO] Copying jersey-client-2.33.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jersey-client-2.33.jar [INFO] Copying jetty-http-9.4.28.v20200408.jar to /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/dependency/jetty-http-9.4.28.v20200408.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ simple-heroku-webapp --- [INFO] Installing /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/target/simple-heroku-webapp.war to /app/tmp/cache/.m2/repository/com/example/simple-heroku-webapp/1.0-SNAPSHOT/simple-heroku-webapp-1.0-SNAPSHOT.war [INFO] Installing /tmp/build_992cc747-26d6-4800-bdb1-add47b9583cd/pom.xml to /app/tmp/cache/.m2/repository/com/example/simple-heroku-webapp/1.0-SNAPSHOT/simple-heroku-webapp-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.857 s [INFO] Finished at: 2021-01-29T09:13:23+01:00 [INFO] ------------------------------------------------------------------------ -----> Discovering process types Procfile declares types -> web -----> Compiled slug size: 75.9MB -----> Launching... done, v6 http://simple-heroku-webapp.herokuapp.com deployed to Heroku To git@heroku.com:simple-heroku-webapp.git * [new branch] master -> master
Now you can access your application at, for example: http://simple-heroku-webapp.herokuapp.com/myresource
In the sections above, we have covered an approach how to get dirty with Jersey quickly. Please consult the other sections of the Jersey User Guide to learn more about Jersey and JAX-RS. Even though we try our best to cover as much as possible in the User Guide, there is always a chance that you would not be able to get a full answer to the problem you are solving. In that case, consider diving in our examples that provide additional tips and hints to the features you may want to use in your projects.
Jersey codebase contains a number of useful examples on how to use various JAX-RS and Jersey features. Feel free to browse through the code of individual Jersey Examples in the Jersey source repository. For off-line browsing, you can also download a bundle with all the examples from here.