6.2.2. Deployment in WAR

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.

  1. 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}'
        }
    }
  2. Add the task to build a distribution to build.gradle:

    task createWarDistr(dependsOn: [coreModule.buildWar, webModule.buildWar], type: CubaWarDistribution) {
        appHome = '${app.home}'
    }
  3. Start build process:

    gradlew createWarDistr

    As a result, the home directory named ${app.home} and the app-core.war and app.war files are created in the build/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.

  4. Copy the content of build/war/${app.home} to the server, for example, to the /home/user/app_home directory.

  5. Install the Glassfish 4 server, for example, into the /home/user/glassfish4 directory.

  6. Copy the JDBC driver of the database to the /home/user/glassfish4/glassfish/domains/domain1/lib directory. You can take the driver file from the lib directory in Studio, or from the build/tomcat/lib project directory (if fast deployment in Tomcat has been performed before).

  7. Start the server:

    $ cd /home/user/glassfish4/bin

    $ ./asadmin start-domain

  8. Go to http://localhost:4848 and do the following steps in the server management console:

    1. 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

    2. Create a JDBC Resource:

      • JNDI Name: jdbc/CubaDS

      • Pool Name: AppDB

    3. 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.

  9. Restart the server:

    $ ./asadmin stop-domain

    $ ./asadmin start-domain

  10. Open the server console at http://localhost:4848 and, in the Applications screen, perform deployment of the app-core.war and app.war files located in the distribution folder created in Step 3.

  11. 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