7.3.2. WAR deployment to Jetty
Below is an example of deployment of the WAR files to the Jetty web server. It is assumed that the application uses a PostgreSQL database.
-
Use Deployment settings > WAR page in Studio or just manually add the buildWar task to the end of build.gradle:
task buildWar(type: CubaWarBuilding) { appHome = '${app.home}' appProperties = ['cuba.automaticDatabaseUpdate': 'true'] singleWar = false }
Please note that we are building two separate WAR files for Middleware and Web Client blocks here.
-
Start build process by running
buildWar
from the Search dialog in Studio or from the command line (provided that you have created the Gradle wrapper beforehand):gradlew buildWar
As a result, the
app-core.war
andapp.war
files will be created in thebuild\distributions\war
project subdirectory. -
Create an application home directory, for example,
c:\work\app_home
. -
Download and install Jetty to a local directory, for example,
c:\work\jetty-home
. This example has been tested onjetty-distribution-9.3.6.v20151106.zip
. -
Create the
c:\work\jetty-base
directory, open the command prompt in it and execute:java -jar c:\work\jetty-home\start.jar --add-to-start=http,jndi,deploy,plus,ext,resources
-
Create the
c:\work\jetty-base\app-jetty.xml
file with the following contents (for a PostgreSQL database namedtest
):<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <New id="CubaDS" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/CubaDS</Arg> <Arg> <New class="org.postgresql.ds.PGSimpleDataSource"> <Set name="ServerName">localhost</Set> <Set name="PortNumber">5432</Set> <Set name="DatabaseName">test</Set> <Set name="User">cuba</Set> <Set name="Password">cuba</Set> </New> </Arg> </New> </Configure>
-
Add the following text to the beginning of
c:\work\jetty-base\start.ini
file:--exec -Xdebug -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n -Dapp.home=c:\work\app_home -Dlogback.configurationFile=c:\work\app_home\logback.xml # --------------------------------------- app-jetty.xml
-
Copy the JDBC driver for your database to the
c:\work\jetty-base\lib\ext
directory. You can take the driver file from the CUBA Studiolib
directory or from thebuild\tomcat\lib
project directory. In case of PostgreSQL database, it ispostgresql-9.1-901.jdbc4.jar
. -
Copy WAR files to the
c:\work\jetty-base\webapps
directory. -
Open the command prompt in the
c:\work\jetty-base
directory and run:java -jar c:\work\jetty-home\start.jar
-
Open
http://localhost:8080/app
in your web browser.