此内容没有您所选择的语言版本。

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.

Note

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>
Copy to Clipboard Toggle word wrap

Thorntail then includes the jaxrs fraction during the build automatically.

Prerequisites

  • An existing Maven-based application with a pom.xml file.

Procedure

  1. Add the thorntail-maven-plugin to your pom.xml in a <plugin> block, with an <execution> specifying the package 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>
    Copy to Clipboard Toggle word wrap
  2. Perform a normal Maven build:

    $ mvn package
    Copy to Clipboard Toggle word wrap
  3. Execute the resulting uberjar:

    $ java -jar ./target/myapp-thorntail.jar
    Copy to Clipboard Toggle word wrap

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

  1. Add the BOM to your pom.xml. For more information, see Chapter 6, Using a BOM.
  2. Add the Thorntail Maven plugin to your pom.xml. For more information, see Section 9.2, “Creating an uberjar”.
  3. Add one or more dependencies on Thorntail fractions to the pom.xml file:

    <dependencies>
      <dependency>
        <groupId>io.thorntail</groupId>
        <artifactId>jaxrs</artifactId>
      </dependency>
    </dependencies>
    Copy to Clipboard Toggle word wrap
  4. Perform a normal Maven build:

    $ mvn package
    Copy to Clipboard Toggle word wrap
  5. Execute the resulting uberjar:

    $ java -jar ./target/myapp-thorntail.jar
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat