Java EE 7 Simple Sample is a trivial Java EE 7 sample application.
-
Clone the repo:
git clone https://github.com/javaee-samples/javaee7-simple-sample.git
-
Build the application:
mvn clean package
Start WildFly server as:
docker run --name wildfly -d -p 8080:8080 -v /Users/youruser/javaee7-simple-sample/target:/opt/jboss/wildfly/standalone/deployments/:rw jboss/wildfly
Make sure to replace /Users/youruser/javaee7-simple-sample/target
to the target directory of your checked out project.
This command starts a container named “wildfly”.
The -v
flag maps a directory from the host into the container. This will be the directory to put the deployments. rw
ensures that the Docker container can write to it.
Warning
|
Windows users, please make sure to use -v /c/Users/ notation for drive letters.
|
Check logs to verify if the server has started.
docker logs -f wildfly
Access http://dockerhost:8080 in your browser to make sure the instance is up and running.
Now you’re ready to deploy the application for the first time.
Start JBoss Developer Studio, if not already started.
-
Select ‘Servers’ tab, create a new server adapter
-
Assign an existing or create a new WildFly 9.0.0 runtime (changed properties are highlighted.)
-
If a new runtime needs to be created, pick the directory for WildFly 9.0.0:
Click on ‘Finish’.
-
Double-click on the newly selected server to configure server properties:
The host name is specified to ‘dockerhost’. Two properties on the left are automatically propagated from the previous dialog. Additional two properties on the right side are required to disable to keep deployment scanners in sync with the server.
-
Specify a custom deployment folder on Deployment tab of Server Editor
-
Right-click on the newly created server adapter and click ‘Start’.
-
Import javaee7-simple-sample application source code using Import → Existing Maven Projects.
-
Right-click on the project, select ‘Run on Server’ and chose the previously created server.
The project runs and displays the start page of the application.
Congratulations!
You’ve deployed your first application to WildFly running in a Docker container from JBoss Developer Studio.
Stop WildFly container when you’re done.
docker stop wildfly
The Command Line Interface (CLI) is a tool for connecting to WildFly instances to manage all tasks from command line environment. Some of the tasks that you can do using the CLI are:
-
Deploy/Undeploy web application in standalone/Domain Mode.
-
View all information about the deployed application on runtime.
-
Start/Stop/Restart Nodes in respective mode i.e. Standalone/Domain.
-
Adding/Deleting resource or subsystems to servers.
Lets use the CLI to deploy javaee7-simple-sample to WildFly running in the container.
-
CLI needs to be locally installed and comes as part of WildFly. This should be available in the previously downloaded WildFly. Unzip into a folder of your choice (e.g.
/Users/arungupta/tools/
). This will createwildfly-9.0.0.Final
directory here. This folder is referred to $WIDLFY_HOME from here on. Make sure to add the/Users/arungupta/tools/wildfly-9.0.0.Final/bin
to your $PATH. -
Run the “wildfly-management” image with fixed port mapping as explained in [Management_Fixed_Port_Mapping].
-
Run the
jboss-cli
command and connect to the WildFly instance.jboss-cli.sh --controller=dockerhost:9990 -u=admin -p=docker#admin -c
This will show the output as:
[standalone@dockerhost:9990 /]
-
Deploy the application as:
deploy <javaee7-simple-sample PATH>target/javaee7-simple-sample-1.10.war --force
Now you’ve sucessfully used the CLI to remote deploy the Java EE 7 sample application to WildFly running as docker container.
WildFly comes with a web-based administration console. It also relies on the same management APIs that are used by JBoss Developer Tools and the CLI. It provides a simple and easy to use web-based console to manage WildFly instance. For a Docker image, it needs to be explicitly enabled as explained in [Enabling_WildFly_Administration]. Once enabled, it can be accessed at http://dockerhost:9990.
Username and password credentials are shown in [WildFly_Administration_Credentials].
Note
|
You may like to stop and remove the Docker container running WildFly. This can be done as Start a new container as |
Deploy the application using the console with the following steps:
-
Go to ‘Deployments’ tab.
-
Click on ‘Add’ button.
-
On ‘Add Deployment’ screen, take the default of ‘Upload a new deployment’ and click ‘Next>>’.
-
Click on ‘Choose File’, select
<javaee7-simple-sample PATH>/javaee7-simple-sample.war
file on your computer. This would bejavaee7-simple-sample/target/javaee7-simple-sample.war
from Build Application. -
Click on ‘Next>>’.
-
Select ‘Enable’ checkbox.
-
Click ‘Finish’.
This will complete the deployment of the Java EE 7 application using Web Console. The output can be seen out http://dockerhost:8080/javaee7-simple-sample and looks like:
A standalone WildFly process, process can be configured to listen for remote management requests using its “native management interface”. The CLI tool that comes with the application server uses this interface, and user can develop custom clients that use it as well. By default, WildFly management interface listens on 127.0.0.1. When running inside a Docker container, the network interface should be bound to all publicly assigned addresses. This can be easily changed by biding to 0.0.0.0 instead of 127.0.0.1.
-
Start another WildFly instance again:
docker run -d --name wildfly -p 8080:8080 -p 9990:9990 arungupta/wildfly-management
In addition to application port 8080, the administration port 9990 is exposed as well. The WildFly image that is used has tweaked the start script such that the management interface is bound to 0.0.0.0.
-
Create a new server adapter in JBoss Developer Studio and name it “WildFly 9.0.0-Management”. Specify the host name as ‘dockerhost’.
-
Click on ‘Next>’ and change the values as shown.
-
Take the default values in ‘Remote System Integration’ and click on ‘Finish’.
-
Change server properties by double clicking on the newly created server adapter. Specify admin credentials (username: docker, password: docker#admin). Note, you need to delete the existing password and use this instead:
-
Right-click on the newly created server adapter and click ‘Start’. Status quickly changes to ‘Started’ as shown.
-
Right-click on the javaee7-simple-sample project, select ‘Run on Server’ and choose this server. The project runs and displays the start page of the application.
-
Stop WildFly when you’re done.
docker stop wildfly