JavaEE standard application deployment into WAR files is performed using the buildWar and createWarDistr build tasks. An example of building WAR files and their deployment on the Glassfish 4 server is provided below.
-
Add tasks to build WAR for the core and web modules to build.gradle:
configure(coreModule) { ... task buildWar(dependsOn: assemble, type: CubaWarBuilding) { appName = 'app-core' appHome = '${app.home}' } } configure(webModule) { ... task buildWar(dependsOn: assemble, type: CubaWarBuilding) { appName = 'app' appHome = '${app.home}' } }
-
Add the task to build a distribution to
build.gradle
:task createWarDistr(dependsOn: [coreModule.buildWar, webModule.buildWar], type: CubaWarDistribution) { appHome = '${app.home}' }
- Start build process:
gradlew createWarDistr
As a result, the home directory named
${app.home}
and theapp-core.war
andapp.war
files are created in thebuild/war
project subdirectory. Name of the home directory does not matter here, as the actual name will be set for the server using a Java system variable. -
Copy the content of
build/war/${app.home}
to the server, for example, to the/home/user/app_home
directory. -
Install the Glassfish 4 server, for example, into the
/home/user/glassfish4
directory. -
Copy the JDBC driver of the database to the
/home/user/glassfish4/glassfish/domains/domain1/lib
directory. You can take the driver file from thelib
directory in Studio, or from thebuild/tomcat/lib
project directory (if fast deployment in Tomcat has been performed before). -
Start the server:
$ cd /home/user/glassfish4/bin
$ ./asadmin start-domain
-
Go to
http://localhost:4848
and do the following steps in the server management console:-
Create a JDBC Connection Pool to connect to our database, for example:
-
Pool Name: AppDB
-
Resource Type: javax.sql.DataSource
-
Database Driver Vendor: Postgresql
-
Datasource Classname: org.postgresql.ds.PGSimpleDataSource
-
User: cuba
-
DatabaseName: app_db
-
Password: cuba
-
-
Create a JDBC Resource:
-
JNDI Name: jdbc/CubaDS
-
Pool Name: AppDB
-
-
In the server (Admin Server) -> Properties -> System Properties screen, set the following Java system variables:
-
app.home = /home/user/app_home
– application home directory. -
log4j.configuration = file:///home/user/app_home/log4j.xml
– application logging configuration file.
-
-
- Restart the server:
$ ./asadmin stop-domain
$ ./asadmin start-domain
-
Open the server console at
http://localhost:4848
and, in the Applications screen, perform deployment of theapp-core.war
andapp.war
files located in the distribution folder created in Step 3. -
The application has now been started:
-
Web interface is available at
http://localhost:8080/app
-
Log files are created in the
/home/user/app_home/logs
-