In this tutorial Java EE example application on Openshift we have deployed a sample Java EE application using a database on Openshift. We will explore now other possibilities such as providing a custom application server configuration, a set of custom modules and finally we will learn how to add artifacts directly into the deployments folder of the application server.
Starting WildFly on Openshift with a custom configuration
So our first project will show how to provide a custom configuration for a WildFly image. Here is the project: https://github.com/fmarchioni/mastertheboss/tree/master/openshift/config
As you can see from the following picture, the custom configuration has to be placed in a cfg folder:
In our case, the custom configuration merely adds a System property that will be inspected by the application placed in the "src" folder:
<system-properties> <property name="greeting" value="Hello World"/> </system-properties>
In order to build the application on Openshift specify the root folder as Git Repository URL: https://github.com/fmarchioni/mastertheboss
Next, specify the subfolder "openshift/config" as path:
Once the application has been built, in the top header of the page it will be displayed the System Property gathered from the custom configuration:
Adding custom modules and deployments to WildFly on Openshift
Our second application, available on github at https://github.com/fmarchioni/mastertheboss/tree/master/openshift/module, will show how to add external modules and deployments during the Source to Image process.
As you can see from the above picture, you can use the following folders:
- modules: Place here modules just like you would do in a bare-metal installation of WildFly. They will be automatically uploaded on WildFly
- deployments: Place here artifacts that are to be deployed on the application server.
├── modules │ └── com │ └── itext │ └── main │ ├── itext-5.0.5.jar │ └── module.xml ├── pom.xml ├── README.md └── src └── main ├── java │ └── com │ └── mastertheboss │ └── CreatePDFExample.java └── webapp ├── index.jsp └── WEB-INF ├── jboss-deployment-structure.xml └── web.xml
The module.xml loads the itext JAR file and uploads it into the application server.
<module xmlns="urn:jboss:module:1.1" name="com.itext"> <properties> <property name="jboss.api" value="private"/> </properties> <resources> <resource-root path="itext-5.0.5.jar"/> </resources> </module>
In order to link the library with the application server add a jboss-deployment-structure.xml file:
<jboss-deployment-structure> <deployment> <dependencies> <module name="com.itext" /> </dependencies> </deployment> </jboss-deployment-structure>
To build the application on Openshift specify the root folder as Git Repository URL: https://github.com/fmarchioni/mastertheboss
Next, specify the subfolder "openshift/modules" as path:
Here is the application in action:
That's all. You can check the rest of the source code on Github: https://github.com/fmarchioni/mastertheboss/tree/master/openshift/module