WildFly Swarm provides an easy solution for deploying Java EE applications as a standalone Jar file. This makes it very easy to deploy applications, particularly REST or web services. Swarm is very similar to Spring Boot in that respect, in that it enables web (.War) applications to be developed quickly and then deployed as standalone applications without the need to deploy an application server.
The WildFly Swarm documentation describes itself as:
Swarm offers an innovative approach to packaging and running Java EE applications by packaging them with just enough of the platform to “java -jar” your application.
Deploying an Java EE application as a Swarm application is fairly straightforward:
- Add dependencies on the aspects of WildFly Swarm that you are to use to your project’s
pom.xml file, for example, JAX-RS or JPA.
- Add the WildFly Swarm plugin to your project’s
pom.xml file to enable an executable Jar file to be created.
- Sit back, relax and run your application as a standalone executable Jar !
To give a demonstration of how easy this is, I’ve created a very simple JAX-RS web service that returns a list of fruits - very similar to the Angular.js factory I created a few years ago.
The code for this sample application is available on GitHub
To create a JAX-RS web service and run as a WlidFly Swarm application, we just need to add the
wildfly-swarm-jaxrs dependency. All of the dependencies that can be used with WildFly Swarm are documented in the User’s Guide
Adding the WildFly Swarm plugin to your
pom.xml to create an executable Jar file is equally simple.
Running The Application
All you need to do now, is perform a
mvn package command to create an executable Jar file which you can start by executing
java -jar myJar.jar
When creating and running a Swarm application, it’s important to note that the URL for the application will be different from when running inside a standalone application server.
When the application is deployed under an application server, the context path with usually include the name of the deloyed application, for example:
When this is deployed as a Swarm application, the context path is not required (there is only one Java EE application running), so the URL will look something more like: