JBoss EAP on App Service demo
In this tutorial you will create a JBoss EAP 7.2 instance on Azure App Service. Once the site is created, you will deploy a demo app and configure the JBoss server to communicate with PostgreSQL.
Have feedback for us? Email us!
Prerequisites
To follow this tutorial, you will need...
- Java 8 installed locally
- Maven installed locally
- An Azure subscription
Tutorial
This tutorial will walk through the process of creating a JBoss EAP site on App Service, deploying a WAR application, and configuring the JBoss EAP server to connect to a PostgreSQL database.
Create a JBoss EAP site
-
Open to the Azure Portal to the Web App create blade. For Runtime stack, select JBoss EAP 7.2 (Preview). JBoss EAP sites can only be created on Premium and Isolated App Service Plans (more information).
-
Once the site is created, browse to the site and you should see the default (aka "parking") page.
-
Open a terminal and clone the Pet Store demo application. We will deploy this app onto the JBoss EAP App Service.
git clone https://github.com/agoncal/agoncal-application-petstore-ee7.git
-
Build the WAR file with
mvn clean install -DskipTests
. -
Deploy the war file to your web app. First, change directories into the sample project,
cd agoncal-application-petstore-ee7
.Powershell
Publish-AzWebapp -ResourceGroupName <group-name> -Name <app-name> -ArchivePath agoncal-application-petstore-ee7\target\applicationPetstore.war
Bash
For bash, you will need to copy the username and password from your app's publishing credentials.
curl -X POST -u <username> --data-binary @"<war-file-path>" https://<app-name>.scm.azurewebsites.net/api/wardeploy
-
Browse to your web app and confirm that the app is now running. This app is using an in-memory H2 database by default. Let's now create a PostgreSQL database and connect it to the application.
Create a PostgreSQL server and database
-
Run the following command to create a Azure Database for PostgreSQL server.
az postgres server create --resource-group <group-name> --name mydemoserver --location westus --admin-user myadmin --admin-password <server_admin_password> --sku-name GP_Gen5_2
-
In the "Connection security" panel of the Azure Database blade, toggle the "Allow access to Azure services" button to the "ON" position. Alternatively, you can run the following CLI command.
az postgres server firewall-rule create -g <group-name> -s <server-name> -n AllowAllWindowsAzureIps --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
Configure JBoss EAP for PostgreSQL
-
Next, we need to edit our Java Transaction API configuration so that our Java application will communicate with Postgres instead of the in-memory H2 database we were using previously. Open an editor to
src/main/resources/META-INF/persistence.xml
. Replace the value for<jta-data-source>
withjava:jboss/datasources/postgresDS
. Your JTA XML should now have this setting:<jta-data-source>java:jboss/datasources/postgresDS</jta-data-source>
-
Create three app settings on the site:
POSTGRES_CONNECTION_URL
: The connection URL for the server, the format should look likejdbc:postgresql://freebergserver123.postgres.database.azure.com:5432/petstore?ssl=true
.POSTGRES_SERVER_ADMIN_FULL_NAME
: The username for the server (provided in the previous command)POSTGRES_SERVER_ADMIN_PASSWORD
: The password for the server (provided in the previous command)
-
Before deploying our reconfigured application, we must update the JBoss application server with the Postgres module and its dependencies. To configure the server we will need the four files in the
db_config/
directory:- postgresql-42.2.12.jar: This .jar is the JDBC driver for Postgres. For more information, please see the official website.
- postgres-module.xml: This XML file declares a name for the Postgres module (org.postgres). It also specifies the resources and dependencies necessary for the module to be used.
- startup_script.sh: Finally, this shell script will be executed whenever your App Service instance is started. The script runs the JBoss CLI commands to configure the server with the data source module, driver, and expose the JNDI name.
- jboss-cli-commands.cli: The JBoss CLI commands that will be executed by the startup script.
-
Using an FTP tool of your choice transfer database driver, XML module descriptor, and cli commands to
/home/site/deployments/tools/
. Upload the startup script to the/home/
path as/home/startup.sh
. App Service will automatically run the startup script if it follows that naming convention. -
Restart the web app. This will cause the web app to run the configuration script.
-
Update
persistence.xml
... <jta-data-source>java:jboss/datasources/postgresDS</jta-data-source> ...
-
Repackage and redeploy using the CLI commands below.
PowerShell
mvn clean install -DskipTests Publish-AzWebapp -ResourceGroupName <group-name> -Name <app-name> -ArchivePath agoncal-application-petstore-ee7\target\applicationPetstore.war
Bash
mvn clean install -DskipTests curl -X POST -u <username> --data-binary @"<war-file-path>" https://<app-name>.scm.azurewebsites.net/api/wardeploy
-
Finally, browse to the web app. The pet store app is configured such that if it cannot connect to Postgres, then it will not start. So if you can see and interact with the Petstore application, then you have successfully completed the tutorial! See the resources below for more info. If you got stuck, please file an issue.