Chapter 5. Using Thorntail fractions
5.1. Fractions
Thorntail is defined by an unbounded set of capabilities. Each piece of functionality is called a fraction. Some fractions provide only access to APIs, such as JAX-RS or CDI; other fractions provide higher-level capabilities, such as integration with RHSSO (Keycloak).
The typical method for consuming Thorntail fractions is through Maven coordinates, which you add to the pom.xml
file in your application. The functionality the fraction provides is then packaged with your application (see Section 9.2, “Creating an uberjar”).
To enable easier consumption of Thorntail fractions, a bill of materials (BOM) is available. For more information, see Chapter 6, Using a BOM.
5.2. Auto-detecting fractions
Migrating existing legacy applications to benefit from Thorntail is simple when using fraction auto-detection. If you enable the Thorntail Maven plugin in your application, Thorntail detects which APIs you use, and includes the appropriate fractions at build time.
By default, Thorntail only auto-detects if you do not specify any fractions explicitly. This behavior is controlled by the fractionDetectMode
property. For more information, see the Maven plugin configuration reference.
For example, consider your pom.xml
already specifies the API .jar
file for a specification such as JAX-RS:
<dependencies> <dependency> <groupId>org.jboss.spec.javax.ws.rs</groupId> <artifactId>jboss-jaxrs-api_2.1_spec</artifactId> <version>${version.jaxrs-api}</version> <scope>provided</scope> </dependency> </dependencies>
Thorntail then includes the jaxrs
fraction during the build automatically.
Prerequisites
-
An existing Maven-based application with a
pom.xml
file.
Procedure
Add the
thorntail-maven-plugin
to yourpom.xml
in a<plugin>
block, with an<execution>
specifying thepackage
goal.<plugins> <plugin> <groupId>io.thorntail</groupId> <artifactId>thorntail-maven-plugin</artifactId> <version>${version.thorntail}</version> <executions> <execution> <id>package</id> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin> </plugins>
Perform a normal Maven build:
$ mvn package
Execute the resulting uberjar:
$ java -jar ./target/myapp-thorntail.jar
Related Information
5.3. Using explicit fractions
When writing your application from scratch, ensure it compiles correctly and uses the correct version of APIs by explicitly selecting which fractions are packaged with it.
Prerequisites
-
A Maven-based application with a
pom.xml
file.
Procedure
-
Add the BOM to your
pom.xml
. For more information, see Chapter 6, Using a BOM. -
Add the Thorntail Maven plugin to your
pom.xml
. For more information, see Section 9.2, “Creating an uberjar”. Add one or more dependencies on Thorntail fractions to the
pom.xml
file:<dependencies> <dependency> <groupId>io.thorntail</groupId> <artifactId>jaxrs</artifactId> </dependency> </dependencies>
Perform a normal Maven build:
$ mvn package
Execute the resulting uberjar:
$ java -jar ./target/myapp-thorntail.jar
Related Information