第 3 章 Thorntail 应用程序 Maven 项目迁移

红帽构建的 Thorntail 即将结束其生命周期。如果您有一个 Thorntail 应用,您可以将应用的 Maven 项目迁移到 JBoss EAP XP。Thorntail 应用程序通过两种方式打包:

  • 将 Thorntail 运行时打包为 Uberjar,一个可执行 JAR,
  • 打包在标准 WAR 存档中,以在 Thorntail 尾部 JAR 中部署和运行,这是仅运行时可执行文件 JAR.

迁移至 JBoss EAP XP 时,可以将 Thorntail 应用打包为可引导 JAR 并修剪 JBoss EAP XP 运行时,以包含 MicroProfile 平台和应用依赖的其他技术。

将应用迁移到 JBoss EAP XP 时,您必须移除任何 Thorntail 部分依赖项,并将任何必需的 MicroProfile 和 Jakarta EE 8 规范的构件添加到 Maven 项目依赖项中。

注意

您可以在运行时使用 JBoss CLI 工具或 JBoss EAP Web 控制台来更改服务器配置。但是,与打包期间所做的配置更改不同,在运行时对配置所做的任何更改都不会保留,在您重新启动可引导 JAR 时会丢失。

3.1. 将 Thorntail 应用 Maven 项目迁移到 JBoss EAP XP

如果您的 Thorntail 应用程序依赖于诸如 Jakarta Enterprise Beans、Jakarta 服务器 Faces、Jakarta Connector API、SOAP Web 服务或 CORBA 等技术,您可以将应用程序的 Maven 项目迁移到 JBoss EAP XP。

Galleon 层用于配置 JBoss EAP XP 运行时在可引导 JAR 中打包的功能。当您迁移使用 Jakarta EE 8 规格的 Thorntail 应用程序时,您必须将相关的 Galleon 层添加到可引导 JAR Maven 插件配置中。

使用 Galleon 层时,JBoss EAP XP 生成服务器配置并将其打包在可引导 JAR 中。如果没有使用 Galleon 层,则在可引导 JAR 中打包与默认 standalone-microprofile.xml 相同的配置。

如果您使用 <cloud> 配置元素为云构建可引导 JAR,则与默认的 standalone-microprofile-ha.xml 类似的 OpenShift 配置将应用到您的可引导 JAR。

可引导 JAR Maven 插件在打包可引导 JAR 的 JAR 时执行 JBoss CLI 脚本。

流程

  1. 删除任何 Thorntail BOM 导入。

    pom .xml 文件中删除 theio.thorntail Thorntail BOM 导入的示例:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>io.thorntail</groupId>
          <artifactId>bom</artifactId>
          <version>${version.thorntail}</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>

  2. 使用 JBoss EAP XP BOM 将受支持的构件导入到 JBoss EAP XP 依赖关系管理。

    使用 jboss-eap-jakartaee8-with-tools BOM 将支持的工件导入到项目中的示例。

    <dependencyManagement>
            <dependencies>
                <!-- importing the jakartaee8-with-tools BOM adds specs and other useful artifacts as managed dependencies -->
                <dependency>
                    <groupId>org.jboss.bom</groupId>
                    <artifactId>jboss-eap-jakartaee8-with-tools</artifactId>
                    <version>${version.server.bom}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <!-- importing the microprofile BOM adds MicroProfile specs -->
                <dependency>
                    <groupId>org.jboss.bom</groupId>
                    <artifactId>jboss-eap-xp-microprofile</artifactId>
                    <version>${version.microprofile.bom}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

    注意

    仅当应用依赖于 MicroProfile 平台中未包含的 Jakarta EE 8 规范时,导入 jakartaee8-with-tools BOM。

  3. 将 Thorntail Maven 插件替换为 JBoss EAP XP 可引导 JAR Maven 插件。

    演示如何将 Thorntail Maven 插件替换为 JBoss EAP XP 可引导 JAR Maven 插件。

    <plugin>
       <groupId>org.wildfly.plugins</groupId>
       <artifactId>wildfly-jar-maven-plugin</artifactId>
       <version>${bootable.jar.maven.plugin.version}</version>
       <configuration>
          <feature-pack-location>${org.jboss.eap:wildfly-galleon-pack:${jboss.xp.galleon.feature.pack.version}</feature-pack-location>
          <layers>
             <layer>microprofile-platform</layer>
          </layers>
       </configuration>
       <executions>
          <execution>
             <goals>
                <goal>package</goal>
             </goals>
          </execution>
       </executions>
    </plugin>

    注意

    上例为 Maven 插件版本指定以下属性:

    ${bootable.jar.maven.plugin.version}

    您必须将 Maven 插件版本设置为在项目中替换此属性。例如:

    <properties>
        <bootable.jar.maven.plugin.version>4.0.3.Final-redhat-00001</bootable.jar.maven.plugin.version>
    </properties>
    • 可引导 JAR 插件默认构建 UberJAR,这意味着它将 JBoss EAP XP 运行时与所部署的应用进行打包。要构建 hollow JAR,请在插件配置中添加 <hollow-jar>true</hollow-jar >。
  4. 对 Maven 项目中的 Thorntail 部分进行以下更改:

    1. 删除 Thorntail 部分依赖项。

      显示从 Maven 项目删除 the io.thorntail Thorntail 部分的示例。

      <dependencies>
        <dependency>
          <groupId>io.thorntail</groupId>
          <artifactId>jaxrs</artifactId>
        </dependency>
      </dependencies>

    2. 配置 Maven 依赖项。

      使用 XML 代码段添加依赖项到 Jakarta EE 8 JAX-RS 和 MicroProfile Config API 的构件的示例。

      <dependencies>
          <!-- Import the MicroProfile Config API, we use provided scope as the API is included in the server -->
          <dependency>
            <groupId>org.eclipse.microprofile.config</groupId>
            <artifactId>microprofile-config-api</artifactId>
            <scope>provided</scope>
          </dependency>
          <!-- Import the Jakarta REST API, we use provided scope as the API is included in the server -->
          <dependency>
            <groupId>org.jboss.spec.javax.ws.rs</groupId>
            <artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
            <scope>provided</scope>
          </dependency>
        </dependencies>

    3. 删除 Thorntail YAML 文件、系统属性和环境属性。
    4. 配置 Galleon 层.

      为需要 JAX-RS 的应用在可引导 JAR Maven 插件中配置 Galleon 层的示例:

      <plugin>
        <groupId>org.wildfly.plugins</groupId>               <artifactId>wildfly-jar-maven-plugin</artifactId>                  <configuration>
         ...
            <layers>
              <layer>jaxrs-server</layer>
              <layer>microprofile-platform</layer>
            </layers>
        </configuration>
         ...
      </plugin>

其他资源