2
0
Fork 0
mirror of https://github.com/ethauvin/rife2-hello.git synced 2025-04-24 15:07:11 -07:00
Bootstrap project structure to create a RIFE2 web application
Find a file
Cedric Champeau 2e025cd693 Rework Gradle build
This commit introduces a _convention plugin_ for RIFE2 support.
It provides a number of advantages:

- the build logic is clearly separated from the build script,
which now only contains user-specific configuration, like the
framework version or how to configure test logging
- it fixes a number of issues like hardcoded dependencies
(`dependsOn` is in general a mistake)
- it removes the need to resolve the agent path eagerly
- it makes the agent configurable
- it clearly separates the user classpath from the RIFE
classpath (both for precompiling templates and for the agent)
- template compilation is cached
- it avoids the abuse of `src/main/resources` to put
templates and uses a dedicated directory instead, which
removes the need for exclusions

In addition, this should make it relatively straightforward
to convert the convention plugin into a proper RIFE2 plugin,
by extracting the code in `build-logic` into its own
repository then publishing to the Gradle plugin portal.
2023-02-21 23:52:36 +01:00
.github/workflows Added GitHub workflow action 2023-02-12 13:08:51 -05:00
app Rework Gradle build 2023-02-21 23:52:36 +01:00
build-logic Rework Gradle build 2023-02-21 23:52:36 +01:00
gradle/wrapper Initial commit 2023-02-12 11:39:35 -05:00
war Updated for RIFE2 1.1.1. 2023-02-13 08:30:34 -05:00
.gitattributes Initial commit 2023-02-12 11:39:35 -05:00
.gitignore Added readme and updated git ignore. 2023-02-12 11:45:36 -05:00
gradle.properties Rework Gradle build 2023-02-21 23:52:36 +01:00
gradlew Initial commit 2023-02-12 11:39:35 -05:00
gradlew.bat Initial commit 2023-02-12 11:39:35 -05:00
LICENSE Initial commit 2023-02-12 11:37:38 -05:00
README.md Merge remote-tracking branch 'origin/main' 2023-02-19 10:32:22 -05:00
settings.gradle.kts Rework Gradle build 2023-02-21 23:52:36 +01:00

License Java GitHub CI

Watch the video

RIFE2 bootstrap project structure

This project helps you to get started with a RIFE2 web application and Gradle.

You'll find all the pieces that are explained in the first sections of the documentation neatly contained in this one project.

It's ready to run, package and deploy ... and for you to have fun developing in a very iterative, intuitive and rewarding way.

For all things RIFE2, head on to the project website: https://rife2.com

Run the tests

./gradlew clean test

Running the server

./gradlew clean run

Go to:

http://localhost:8080/

Deploying the app

./gradlew clean war

The resulting archive will be in: war/build/libs

If you use any of the byte-code instrumented features , like continuations, metadata merging or lazy-loaded database entities, you'll need to launch your servlet container with the -javaagent:[path-to]/rife2-[version]-agent.jar argument. Exactly how is dependent on each servlet container.

For example, for Apache Tomcat this is typically done by customizing the CATALINA_OPTS environment variable, for instance:

CATALINA_OPTS="-javaagent:[path-to]/rife2-[version]-agent.jar" ./bin/catalina.sh run

For Jetty, it could just be an argument of the java call:

java -javaagent:[path-to]/rife2-[version]-agent.jar -jar $JETTY_HOME/start.jar

Making an UberJar

./gradlew clean uberJar

Then run it with:

java -jar app/build/libs/hello-uber-1.0.jar

If you use any of the byte-code instrumented features, you'll need to also tell java to use the RIFE2 agent.

For example:

java -javaagent:[path-to]/rife2-[version]-agent.jar -jar app/build/libs/hello-uber-1.0.jar

Making a native executable

GraalVM supports creating a single Ahead-Of-Time native executable from your java bytecode.

Once you have at least GraalVM 22.3.1 Java 19 installed, you can generate the UberJar as above, then create your native binary as such:

native-image --no-fallback --enable-preview -jar app/build/libs/hello-uber-1.0.jar

You'll end up with a hello-uber-1.0 file that can be executed directly without the need of a JVM:

./hello-uber-1.0

NOTE: RIFE2 support for GraalVM native-image is still in preliminary stages. There's no solution yet to replace the features of the RIFE2 Java agent, and it's only been tested in a limited context. When expanding the code of the project, you most likely will have to update the native-image configuration files located in app/src/main/resources/META-INF/native-image. More information about that can be found in the GraalVM manual.

Get in touch

Thanks for using RIFE2!

If you have any questions, suggestions, ideas or just want to chat, feel free to post on the forums, to join me on Discord or to connect with me on Mastodon.

Read more in the full documentation and RIFE2 Javadocs.