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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Deploy Application on Open-Shift that Requires Elevated Privileges on Specific Paths
  • 13-Step Guide to Performance Testing in Kubernetes
  • GenAI: From Prompt to Production
  • Running a Mobile App API Locally With Docker and Postman

Trending

  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Top Book Picks for Site Reliability Engineers
  1. DZone
  2. Coding
  3. Tools
  4. Deploy to WildFly and Docker From IntelliJ Using Management API

Deploy to WildFly and Docker From IntelliJ Using Management API

When you are new to both Docker and IntelliJ how do you deploy your Java EE applications? Steve Favez shows you how.

By 
Steve Favez user avatar
Steve Favez
·
Apr. 21, 16 · Tutorial
Likes (11)
Comment
Save
Tweet
Share
26.8K Views

Join the DZone community and get the full member experience.

Join For Free

As a new Docker and IntelliJ user, I was looking for some tips on how to deploy an application from my IDE to a running wildfly docker container. Searching the web returned me some tech tips, but only based on Eclipse/JBoss tools.

So, I decided to share a quick summary of how to deploy a Java EE 7 application to WildFly and Docker from Intellij(2016), using the WildFly management API.

This JBoss tools tutorial (Part 1 and Part 2 ) was really helpful .

Customizing the jboss/wildfly image

This tutorial is based on the official jboss/wildfly docker image.

In order to access wildfy management API remotely (that’s the case with Docker), you’ll need to customize jboss/wildfly image to expose management port outside of the container. So, let’s create a new Dockerfile.

FROM jboss/wildfly:latest    
USER jboss  RUN /opt/jboss/wildfly/bin/add-user.sh admin Jboss@admin01 --silent  
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "--debug"]


As you can see, we’re extending jboss/wildfly image (latest version – so, wildfly 10 now), sudo to user « jboss » (the one used to execute wildfly process in the dock), add a new management user using « add-user.sh » in silent mode (user is admin, with password  Jboss@admin01) and change the default command exposing management port to the outside world and starting in debug mode.

Building Your New jboss/wildfly image

Right now, you need to build your new Docker image, using docker build. You can have named it as you want. For this tutorial, let’s name it «jboss/wildfly-dev»

This can be done using the following command in the directory containing your new Dockerfile (don’t forget the «.» in the end):

docker build /wildfly-dev .

Running Your New jboss/wildfly-dev Image

After a successful build, you’re now ready to run your new image, by executing the following command:

docker run -it -p 8080:8080 -p 9990:9990 -p 8787:8787 jboss/wildfly-dev

This will run in interactive mode your new container, exposing port 8080 for your application, 9990 for the management api and 8787 for remote debugging.

Type the following URL in your favorite browser to ensure your wildfly is properly started: http://192.168.99.100:8080

You can also check that your «admin» user exists by typing:  http://192.168.99.100:9990

ATTENTION: please, check your docker IP address using the following command if you’re using docker-machine:

docker-machine env

Create a Sample Web Project in IntelliJ

In order to test hot swap, let’s create a simple restful web service (yes, yet another «hello world» restful project in your life).

You can find the pom.xml and the two java classes on github. The restful service implementation is trivial – it’s just an http GET logging and returning a hello world message:

package org.docker.demo;    
import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;    
import javax.ws.rs.GET;  
import javax.ws.rs.Path;  
import javax.ws.rs.Produces;    
/**   * Created by Steve Favez on 14.04.2016.   
* Yet another Hello world restfull service implementation. Just a "GET" returning a plain hello world message.   *   
*/ 
@Path("/sayhello")  public class YahwRs {     
  private final static Logger LOGGER = LoggerFactory.getLogger(YahwRs.class) ; 

  // The Java method will process HTTP GET requests  
  @GET  // The Java method will produce content identified by the MIME Media type "text/plain" 
  @Produces("text/plain")   
  public String sayHelloWorldPlease() {      
    final String yahwMessage = "Hello world from a restful service deployed in wildfy, in docker and eventually, in  virtualbox" ;
    LOGGER.info( yahwMessage );  
    return yahwMessage ;  
  } 
}


In your IDE, please run a maven package, in order to generate the corresponding web archive.

Configure a Remote Wildfly Server in IntelliJ

Now, you need to create a new « Run » configuration in your project.

Go to menu « Run -> Edit configurations… ».

Image title


Click the « + » button to create a new one and choose « Jboss Server -> Remote »

First Tab ( Server )

Choose a name (in our case, « docker-wildfly »)

If not already configured, choose a corresponding local wildfly installation (same version than the one in your docker image)

In Jboss server settings, set the management port to 9990, Username to « admin » and password to « Jboss@admin01»

And, in remote Connecting Host, enter the IP of your docker container (see docker-machine env)

Image title

Second Tab (Deployment)

Click on the «+» to add an «Artifact», and choose «yahw.war»

Image title

On the right, change «Deployment method» to «Native»

Image title

Last Tab (Startup/Connection)

Click on « debug » and change the default debug port to 8787.

Image title

Debug your project

Here we’re. Now we can deploy our project on our docker/wildfly instance.

 Let’s start by adding a debug breakpoint in our web service (on logging for example), and then choose your new « docker-wildfly » run configuration and click on the « debug » button.

Image title

After a short time, you’ll see a successful deployment, your browser will open a new tab and, if the URL is correct, Intellij will stop on the breakpoint in your web service.

Image title

Perform Hot Swap

Now, let’s perform some Hot Swap.

For example, change the hello world message in your restful web service.

Hot Swap will allow you to push your new implementation to the running server without having to perform a new deployment.

So, click on the «update», it will ask you the action to take, choose hot swap, and, here you’re.

Image title

Conclusion

As you can see, it’s really easy to use a Wildfly Docker container to develop your JEE 7 application with IntellliJ. Using Docker is really useful when your team has to switch frequently of project, requiring heavy WildFly configuration (datasources, jms and so on). Using Docker, a developer can be ready to work on a project really quickly, sharing not only the source code, but also the JEE infrastructure with the team.

Links

Source code can be found on github : https://github.com/stevefavez/docker-labs

Docker (software) API WildFly intellij Web Service

Opinions expressed by DZone contributors are their own.

Related

  • Deploy Application on Open-Shift that Requires Elevated Privileges on Specific Paths
  • 13-Step Guide to Performance Testing in Kubernetes
  • GenAI: From Prompt to Production
  • Running a Mobile App API Locally With Docker and Postman

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!