DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Deploying WildFly Swarm to Heroku

Deploying WildFly Swarm to Heroku

Use WildFly to add support for Java containers in Heroku without going through painful refactoring.

Matthew Casperson user avatar by
Matthew Casperson
·
Apr. 07, 16 · Tutorial
Like (3)
Save
Tweet
Share
4.94K Views

Join the DZone community and get the full member experience.

Join For Free

The rise of cloud services like Heroku left Java EE developers in a bit of a pickle because of the lack of support for Java EE containers. Heroku has some helpful documentation on using Java EE libraries without a container, but this is probably too much refactoring for an established Java EE applications.

Wildfly Swarm neatly avoids this problem by combining application and container into a single deployable artifact. Let’s take a look at what we need to add to the REST API example we created in this article in order for it to boot in Heroku.

First, you are going to need a Heroku account and have installed their toolbelt. The toolbelt provides you with a number of convenient features for managing applications in Heroku.

Once installed, you need to run the following command:

heroku create

From your existing GIT repo. This creates an application in Heroku, and sets up a link between your local GIT repo and one hosted by Heroku. The output of this command should look like this:

$ heroku create

Creating app... done, stack is cedar-14

https://serene-dusk-72188.herokuapp.com/ | https://git.heroku.com/serene-dusk-72188.git

You can verify the new link to the GIT repo host by Heroku with this command:

$ git remote -v

heroku        https://git.heroku.com/serene-dusk-72188.git (fetch)

heroku        https://git.heroku.com/serene-dusk-72188.git (push)

origin        https://github.com/mcasperson/swarmdemo4.git (fetch)

origin        https://github.com/mcasperson/swarmdemo4.git (push)

Before we can start pushing our application up to Heroku, we need to add a new task to the Gradle build script. This task, called stage, does nothing more than trigger the Gradle build. You can find more details on this Gradle task in the Heroku documentation.

task stage {
 dependsOn build
}

Finally, we need a file called Procfile, which Heroku uses to launch the Swarm JAR file. The command we define in this file maps the port exposed by Heroku to Swarm, and configures some memory settings.

I actually found it quite tricky to find memory settings that worked in Heroku. As you can see I had to restrict the Java memory usage quite heavily in order to allow the Swarm application to run with heroku’s memory limits. If you consume too much memory, Heroku will simply kill your app.

web: java -Xmx96m -Xss256k -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=48m -Dswarm.http.port=$PORT -jar build/libs/swarmdemo4-swarm.jar

Deploying you app to Heroku is a case of pushing the source code into the Heroku GIT repo. Heroku will then compile and execute the application.

git push heroku master

You can view the console output of your app with this command:

heroku logs --tail

Image title

I have deployed the mentioned Swarm application to Heroku with these settings, and you can interact with it by visiting https://serene-dusk-72188.herokuapp.com/helloWorld or https://serene-dusk-72188.herokuapp.com/swagger. 

Grab the source code for this application from GitHub.

swarm application Java EE WildFly

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How Do the Docker Client and Docker Servers Work?
  • Kubernetes vs Docker: Differences Explained
  • Distributed SQL: An Alternative to Database Sharding
  • What Is a Kubernetes CI/CD Pipeline?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: