Deployment Gradle
While it's possible to run a RIFE2 application with the embedded Jetty or Tomcat
server in production, it's quite likely that you might want to create a standard
war
archive and deploy your application to another servlet container.
The good news is that you don't need to change anything to your code at all!
RIFE2 provides a standard filter implementation that takes a Site
class name
as its parameter.
In order to deploy the Hello World application, all you need
to do is use the following web.xml
deployment descriptor.
The rifeSiteClass
init parameter has been set to the hello.AppSite
class name,
which will be instantiated by the RifeFilter
as your web application is
deployed.
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<filter>
<filter-name>RIFE2</filter-name>
<filter-class>rife.servlet.RifeFilter</filter-class>
<init-param>
<param-name>rifeSiteClass</param-name>
<param-value>hello.AppSite</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>RIFE2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Create the war
subproject:
mkdir -p war/src
Edit your main settings.gradle.kts
and add war
to the includes:
rootProject.name = "hello"
include("app","war")
Put the web.xml
deployment descriptor from above in your project at
war/src/web.xml
.
Create your subproject build settings at war/build.gradle.kts
:
plugins {
war
}
version = 1.0
base {
archivesName.set("hello")
}
repositories {
mavenCentral()
}
dependencies {
implementation(project(":app"))
}
tasks.war {
webAppDirectory.set(file("../app/src/main/webapp"))
webXml = file("src/web.xml")
}
Now you can use Gradle to build the archive:
gradle war
Your war
archive will be available at war/build/libs/hello-1.0.war
.
Another popular way of deploying a web application is by creating an UberJar. This is a single executable jar archive that contains everything that is necessary to run your application, including the dependencies and resources.
The RIFE2 Gradle plugin you already activated in your project has support for creating an UberJar built .
Simply use the following Gradle command:
gradle uberjar
You'll find the UberJar at app/build/libs/hello-uber-1.0.jar
and to run it,
type the following:
java -jar app/build/libs/hello-uber-1.0.jar
NOTE: You can find these deployment strategies already set up in the RIFE2 GitHub template repository.
Next learn more about Static Resources