2.3. 运行 CLI


您可以针对一个或多个应用程序运行 Migration Toolkit for Applications (MTA) CLI。

在 MTA 7.1.0 之前,如果要针对多个应用程序运行 CLI,您需要对多个应用程序运行一系列 - analyze 命令,每个命令都针对一个应用程序,以及生成单独的报告。此选项仍被完全支持,请参考 针对应用程序运行 MTA CLI

在 MTA 7.1.0 及更新的版本中,您可以使用-- bulk 选项对多个应用程序运行 CLI,以生成单个报告。这个选项(作为开发者预览) 在针对多个应用程序运行 MTA CLI 中描述,并生成单个报告(开发者预览 )。

重要

针对一个或多个应用程序运行 CLI 只是一个技术预览功能。Developer Preview(开发人员预览)功能不被红帽支持,其功能可能并不完善且不是生产环境就绪。不要将开发人员预览功能用于生产环境或业务关键型工作负载。开发人员预览功能可以在之前可能地包含在红帽产品产品中提前访问即将推出的产品功能,使客户能够测试功能并在开发过程中提供反馈。这些功能可能没有任何文档,可能会随时被更改或删除,测试也会受到限制。红帽可能会提供在没有关联 SLA 的情况下提交对开发人员预览功能的反馈。

2.3.1. 针对应用程序运行 MTA CLI

您可以针对应用程序运行 Migration Toolkit for Applications (MTA) CLI。

流程

  1. 打开一个终端,再进入 < MTA_HOME>/ 目录。
  2. 运行 mta-cli 脚本,或为 Windows 运行 mta-cli.exe,并指定适当的参数:

    $ ./mta-cli analyze --input <path_to_input> \
        --output <path_to_output> --source <source_name> --target <target_source> \
    Copy to Clipboard Toggle word wrap
    • --input :要评估的应用程序。
    • --output :所生成的报告的输出目录。
    • --source :应用程序迁移的源技术。例如,weblogic
    • --target :应用程序迁移的目标技术。例如,eap8
  3. 访问报告。

2.3.1.1. MTA 命令示例

在应用程序存档中运行 MTA

以下命令分析名为 jee-example-app-1.0.0.ear 的 EAR 存档示例,用于从 JBoss EAP 5 迁移到 JBoss EAP 7:

$ <MTA_HOME>/mta-cli analyze \
    --input <path_to_jee-example-app-1.0.0.ear> \
    --output <path_to_report_output> --source eap5 --target eap7 \
Copy to Clipboard Toggle word wrap
在源代码上运行 MTA

以下命令分析一个称为 客户管理 (迁移到 JBoss EAP 8)的示例应用的源代码。

$ <MTA_HOME>/mta-cli analyze --mode source-only --input <path_to_customer-management> \
    --output <path_to_report_output> --target eap8 --packages org.jboss.eap
Copy to Clipboard Toggle word wrap
运行云就绪规则

以下命令分析名为 jee-example-app-1.0.0.ear 的 EAR 存档示例,以迁移到 JBoss EAP 7。它还评估云就绪的归档:

$ <MTA_HOME>/mta-cli analyze --input <path_to_jee-example-app-1.0.0.ear> \
    --output <path_to_report_output> \
    --target eap7
Copy to Clipboard Toggle word wrap

现在,您可以针对多个应用程序运行 Migration Toolkit for Applications (MTA) CLI,并生成组合报告。这可以节省时间,并让您更好地了解如何为迁移准备一组应用程序。

此功能目前是开发者技术预览功能。

重要

针对一个或多个应用程序运行 CLI 只是一个技术预览功能。Developer Preview(开发人员预览)功能不被红帽支持,其功能可能并不完善且不是生产环境就绪。不要将开发人员预览功能用于生产环境或业务关键型工作负载。开发人员预览功能可以在之前可能地包含在红帽产品产品中提前访问即将推出的产品功能,使客户能够测试功能并在开发过程中提供反馈。这些功能可能没有任何文档,可能会随时被更改或删除,测试也会受到限制。红帽可能会提供在没有关联 SLA 的情况下提交对开发人员预览功能的反馈。

流程

  1. 打开一个终端,再进入 < MTA_HOME>/ 目录。
  2. 运行 mta-cli 脚本或 Windows 的 mta-cli.exe,并指定适当的参数,为每个 analyze 命令输入一个输入,但为所有输入输入相同的输出目录。例如,要分析应用程序 A、B 和 C:

    1. 输入以下命令输入 A:

      $ ./{mta-cli} analyze --bulk --input=<path_to_input_A> --output=<path_to_output_ABC> --source <source_A> --target <target_A>
      Copy to Clipboard Toggle word wrap
      • --input :要评估的应用程序。
      • --output :所生成的报告的输出目录。
      • --source :应用程序迁移的源技术。例如,weblogic
      • --target :应用程序迁移的目标技术。例如,eap8
    2. 输入以下命令输入 B :

      $ ./{mta-cli} analyze --bulk --input=<path_to_input_B> --output=<path_to_output_ABC>  --source <source_B> --target <target_B>
      Copy to Clipboard Toggle word wrap
    3. 输入以下命令输入 C:

      $ ./{mta-cli} analyze --bulk --input=<path_to_input_C> --output=<path_to_output_ABC>  --source <source_C> --target <target_C>
      Copy to Clipboard Toggle word wrap

      MTA 生成单个报告,列出在迁移应用程序前需要解决的所有问题。

  3. 访问报告。

2.3.3. 使用命令行执行分析

分析 支持使用 分析器运行源代码和二进制分析

要在应用程序源代码上运行分析,请运行以下命令:

mta-cli analyze --input=<path_to_source_code> --output=<path_to_output_directory>
Copy to Clipboard Toggle word wrap

all 标记:

Analyze application source code

Usage:
  mta-cli analyze [flags]

Flags:

      --analyze-known-libraries           Analyze known open-source libraries.
      --context-lines (int)               Number of lines of source code to
                                          include in the output for each
                                          incident (default: `100`).
  -d, --dependency-folders (stringArray)  Directory for dependencies.
      --enable-default-rulesets           Run default rulesets with analysis
                                          (default: `true`).
  -h, --help                              Help for analyze.
      --http-proxy (string)               HTTP proxy string URL.
      --https-proxy (string)              HTTPS proxy string URL.
      --incident-selector (string)        An expression to select incidents
                                          based on custom variables.
                                          Example:
                                          !package=io.demo.config-utils
  -i, --input (string)                    Path to application source code or
                                          a binary.
      --jaeger-endpoint (string)          Jaeger endpoint to collect traces.
      --json-output                       Create analysis and dependency
                                          output as JSON.
      --list-sources                      List rules for available
                                          migration sources.
      --list-targets                      List rules for available
                                          migration targets.
  -l, --label-selector (string)           Run rules based on specified label
                                          selector expression.
      --maven-settings (string)           Path to the custom maven
                                          settings file to use.
      --overwrite                         Overwrite output directory.
      --skip-static-report                Do not generate the static report.
  -m, --mode (string)                     Analysis mode, must be one of
                                          `full` or `source-only`
                                          (default: `full`).
      --no-proxy (string)                 Proxy-excluded URLs
                                          (relevant only with proxy).
  -o, --output (string)                   Path to the directory for analysis
                                          output.
      --overwrite                         Overwrite output directory.
      --rules (stringArray)               Filename or directory containing
                                          rule files.
      --skip-static-report                Do not generate the static report.
  -s, --source (string)                   Source technology to consider
                                          for analysis.
                                          To specify multiple sources,
                                          repeat the parameter:
                                          `--source <source_1>
                                          --source <source_2>` etc.
  -t, --target (string)                   Target technology to consider
                                          for analysis.
                                          To specify multiple targets,
                                          repeat the parameter:
                                          `--target <target_1>
                                          --target <target_2>` etc.


Global Flags:
      --log-level uint32                  Log level (default: 4).
      --no-cleanup                        Do not cleanup temporary resources.
Copy to Clipboard Toggle word wrap
注意

上面的标记列表不包括-- bulk 标志,因为此标志仅作为开发者预览功能的一部分提供。此功能在 CLI 上分析多个应用程序时提供单一报告的支持

使用示例

  1. 获取要运行分析的示例应用程序。
  2. 列出可用的目标技术。

    mta-cli analyze --list-targets
    Copy to Clipboard Toggle word wrap
  3. 使用指定的目标技术运行分析,如 云就绪

    mta-cli analyze --input=<path-to/example-applications/example-1> --output=<path-to-output-dir> --target=cloud-readiness
    Copy to Clipboard Toggle word wrap
  4. 在您指定的输出路径中创建几个分析报告:

    $ ls ./output/ -1
    analysis.log
    dependencies.yaml
    dependency.log
    output.yaml
    static-report
    Copy to Clipboard Toggle word wrap
    • output.yaml 是包含问题报告的文件。
    • static-report 包含静态 HTML 报告。
    • dependencies.yaml 包含依赖项报告。

2.3.4. 使用命令行执行转换

转换有两个子命令 - openrewriterules

Transform application source code or mta XML rules

Usage:
  mta-cli transform [flags]
  mta-cli transform [command]

Available Commands:
  openrewrite Transform application source code using OpenRewrite recipes
  rules       Convert XML rules to YAML

Flags:
  -h, --help   help for transform

Global Flags:
      --log-level uint32   log level (default 4)
      --no-cleanup         do not clean up temporary resources

Use "mta-cli transform [command] --help" for more information about a command.
Copy to Clipboard Toggle word wrap

2.3.4.1. OpenRewrite

openrewrite 子命令允许在源代码上运行 OpenRewrite 方法。

Transform application source code using OpenRewrite recipes

Usage:
  mta-cli transform openrewrite [flags]

Flags:
  -g, --goal string     target goal (default "dryRun")
  -h, --help            help for openrewrite
  -i, --input string    path to application source code directory
  -l, --list-targets    list all available OpenRewrite recipes
  -s, --maven-settings string   path to a custom maven settings file to use
  -t, --target string   target openrewrite recipe to use. Run --list-targets to get a list of packaged recipes.

Global Flags:
      --log-level uint32   log level (default 4)
      --no-cleanup         do not clean up temporary resources
Copy to Clipboard Toggle word wrap

要在应用程序源代码上运行 openrewrite,请运行以下命令:

mta-cli transform openrewrite --input=<path/to/source/code> --target=<exactly_one_target_from_the_list>
Copy to Clipboard Toggle word wrap

注意

您只能使用单个目标来运行 转换覆盖 命令。

2.3.4.2. 规则

rules 子命令允许使用 windup-shim 将 mta XML 规则转换为 analyzer-lsp YAML 规则。

Convert XML rules to YAML

Usage:
  mta-cli transform rules [flags]

Flags:
  -h, --help                help for rules
  -i, --input stringArray   path to XML rule file(s) or directory
  -o, --output string       path to output directory

Global Flags:
      --log-level int   log level (default 5)
Copy to Clipboard Toggle word wrap

要在应用程序源代码上运行 转换规则,请运行以下命令:

mta-cli transform rules --input=<path/to/xmlrules> --output=<path/to/output/dir>
Copy to Clipboard Toggle word wrap

使用示例

  1. 获取示例应用程序来转换源代码。
  2. 查看可用的 OpenRewrite recipes。

    mta-cli transform openrewrite --list-targets
    Copy to Clipboard Toggle word wrap
  3. 在示例应用程序上运行方法。

    mta-cli transform openrewrite --input=<path-to/jakartaee-duke> --target=jakarta-imports
    Copy to Clipboard Toggle word wrap

    检查 jakartaee-duke 应用源代码 diff 以查看转换。

2.3.4.3. 可用的 OpenRewrite recipes

Expand
表 2.1. 可用的 OpenRewrite recipes
迁移路径用途rewrite.configLocationactiveRecipes

Java EE 到 Jakarta EE

使用对等的 jakarta 软件包替换 javax 软件包导入

pom.xml 文件中声明的 javax 工件替换为对等的 jakarta

<MTA_HOME>/rules/openrewrite/jakarta \ /javax/imports/rewrite.yml

org.jboss.windup.JavaxToJakarta

Java EE 到 Jakarta EE

重命名 bootstrap 文件

<MTA_HOME>/rules/openrewrite/jakarta \ /javax/bootstrapping/rewrite.yml

org.jboss.windup.jakarta.javax. \ BootstrappingFiles

Java EE 到 Jakarta EE

转换 persistence.xml 配置

<MTA_HOME>/rules/openrewrite/jakarta \ /javax/xml/rewrite.yml

org.jboss.windup.javax-jakarta. \ PersistenceXML

Spring Boot 到 Quarkus

在文件中替换 spring.jpa.hibernate.ddl-auto 属性来匹配 application*.properties

<MTA_HOME>/rules/openrewrite/quarkus \ /springboot/properties/rewrite.yml

org.jboss.windup.sb-quarkus.Properties

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat