Running a Java WAR File on the Command-Line

Featured image for sharing metadata for article

If you're working with Web WAR files for your web applications, you may want to deploy and test them locally.

In a lot of cases, you are unlikely to have a web server like Tomcat or Jetty installed and ready to go to, especially if you're wanting to test things infrequently.

This evening I've been trying to run the MitreID Connect OpenID Connect reference implementation, which is packaged in a WAR, but I didn't want to set up a web server.

Fortunately, the Jetty web server makes it pretty straightforward to get up and running.

Jetty 9

In pre-Jetty 10, there is the jetty-runner project, which makes it incredibly simple to get up-and-running with a single JAR file.

For instance, say we want to run a WAR under a specific context root, we can run the jetty-runner JAR as below:

java -jar jetty-runner.jar --path /openid-connect-server-webapp openid-connect-server-webapp-1.3.3.war

This then will allow us to access our application running on http://localhost:8080/openid-connect-server-webapp.

The JAR can be downloaded from Maven central - remember to get a 9.x release!

Jetty 10+

Unfortunately in Jetty 10+ the jetty-runner has been made a no-op, so we need a slightly more complex setup, using the jetty-home project.

To get this working with the new version, we need to set up the Jetty base dir by running the following:

# for our pre-downloaded ZIP
unzip jetty-home*.zip
cd jetty-home*
java -jar start.jar --add-module=http
# other modules may be required
cp /path/to/openid-connect-server-webapp-1.3.3.war webapps/openid-connect-server-webapp.war

This then will allow us to access our application running on http://localhost:8080/openid-connect-server-webapp.

The ZIP can be downloaded from Maven central - remember to get a 11.x release!

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #java #war.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.