7.3.3. WAR deployment to WildFly
The WAR files with CUBA application can be deployed to the WildFly application server. An example below demonstrates how to deploy a CUBA application using PostgreSQL 9.6 to the WildFly 8.2 server on Windows.
-
Assemble and deploy the project to the default Tomcat server in order to get all necessary dependencies locally.
-
Configure the application home directory for the application:
-
Create a folder that will be fully available for WildFly server’s process. For example:
C:\Users\UserName\app_home. -
Copy the
logback.xmlfile fromtomcat/confto this folder and edit thelogDirproperty:
<property name="logDir" value="${app.home}/logs"/> -
-
Configure the WildFly server
-
Install WildFly to a local folder, for example, to
C:\wildfly. -
Edit the
C:\wildfly\bin\standalone.conf.batfile and add the following line to the end of the file:
set "JAVA_OPTS=%JAVA_OPTS% -Dapp.home=%USERPROFILE%/app_home -Dlogback.configurationFile=%USERPROFILE%/app_home/logback.xml"Here we define the
app.homesystem property with the application home directory and configure the logging by setting the path to thelogback.xmlfile. You can also use an absolute path instead of%USERPROFILE%variable.-
Compare the Hibernate Validator versions in WildFly and CUBA application (normally, the platform uses a newer version). Replace the
C:/wildfly/modules/system/layers/base/org/hibernate/validator/main/hibernate-validator-x.y.z-sometext.jarwith the newer file fromtomcat/shared/lib, for example,hibernate-validator-5.4.1.Final.jar. -
Update the JAR file version number in the
/wildfly/modules/system/layers/base/org/hibernate/validator/main/module.xmlfile. -
To register PostgreSQL driver in WildFly, copy the
postgresql-9.4-1201-jdbc41.jarfromtomcat/libtoC:\wildfly\standalone\deployments.TipIf you use WildFly 11, in order to install PostgreSQL driver, you should also modify your
module.xmlfile in the following way:<module xmlns="urn:jboss:module:1.1" name="org.postgresql"> <resources> <resource-root path="postgresql-9.4.1212.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>Then you should run
jboss-clifrom thebinfolder and run the following command:/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql, driver-module-name=org.postgresql, driver-class-name=org.postgresql.Driver)
-
-
Create JDBC Datasource
-
Start WildFly by running
standalone.bat -
Open the administration console on
http://localhost:9990. The first time you log in, you will be asked to create a user and a password. -
Open the Configuration - Subsystems - Datasources tab and create a new datasource for your application:
Name: Cuba JNDI Name: java:/jdbc/CubaDS JDBC Driver: postgresql Connection URL: your database URL Username: your database username Password: your database passwordThe JDBC driver will be available on the list of detected drivers if you have copied
postgresql-x.y.z.jaras described above.Check the connection by clicking the Test connection button.
-
Activate the datasource.
-
-
Build the application
-
Open Deployment settings > WAR in Studio.
-
Check Build WAR checkbox.
-
Set
${app.home}in the Application home directory field. -
Check Include JDBC driver checkbox.
-
Save the settings.
-
Open build.gradle in IDE and add the
doAfterproperty to the buildWar task. This property will copy the WildFly deployment descriptor:task buildWar(type: CubaWarBuilding) { includeJdbcDriver = true appProperties = ['cuba.automaticDatabaseUpdate' : true] singleWar = false appHome = '${app.home}' doAfter = { copy { from 'jboss-deployment-structure.xml' into "${project.buildDir}/tmp/core/war/META-INF/" } copy { from 'jboss-deployment-structure.xml' into "${project.buildDir}/tmp/web/war/META-INF/" } } }TipFor a singleWAR configuration the task will be different:
task buildWar(type: CubaWarBuilding) { webXmlPath = 'modules/web/web/WEB-INF/single-war-web.xml' appProperties = ['cuba.automaticDatabaseUpdate' : true] includeJdbcDriver = true appHome = '${app.home}' doAfter = { copy { from 'jboss-deployment-structure.xml' into "${project.buildDir}/tmp/war/META-INF/" } } }If your project also contains a Polymer module, add the following configuration to your
single-war-web.xmlfile:<servlet> <servlet-name>default</servlet-name> <init-param> <param-name>resolve-against-context-root</param-name> <param-value>true</param-value> </init-param> </servlet> -
In the project root folder, create the
jboss-deployment-structure.xmlfile and add the WildFly deployment descriptor to it:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <deployment> <exclusions> <module name="org.apache.commons.logging" /> <module name="org.apache.log4j" /> <module name="org.jboss.logging" /> <module name="org.jboss.logging.jul-to-slf4j-stub" /> <module name="org.jboss.logmanager" /> <module name="org.jboss.logmanager.log4j" /> <module name="org.slf4j" /> <module name="org.slf4j.impl" /> <module name="org.slf4j.jcl-over-slf4j" /> </exclusions> </deployment> </jboss-deployment-structure>-
Run the
buildWartask to create WAR files.
-
-
Copy the files
app-core.warandapp.warfrombuild\distributions\warto WildFly directoryC:\wildfly\standalone\deployments. -
Restart the WildFLy server.
-
Your application will become available on
http://localhost:8080/app. The log files will be saved in the application home:C:\Users\UserName\app_home\logs.