搜索

2.2. 运行 CLI

download PDF

您可以针对您的应用程序运行 MTA。

流程

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

    $ ./mta-cli analyze --input /path/to/jee-example-app-1.0.0.ear \
        --output /path/to/output --source weblogic --target eap6 \
    • --input :要评估的应用程序。
    • --output :所生成的报告的输出目录。
    • --source :应用程序迁移的源技术。
  3. 访问报告。

2.2.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 \
在源代码上运行 MTA

以下命令分析 Migrate -booking-5.2 示例源代码以迁移到 JBoss EAP 6。

$ <MTA_HOME>/mta-cli analyze --mode source-only --input /path/to/seam-booking-5.2/ \
    --output /path/to/report-output/ --target eap6 --packages org.jboss.seam
运行云就绪规则

以下命令分析用于迁移到 JBoss EAP 7 的 jee-example-app-1.0.0.ear 示例 EAR 存档。它还评估了云就绪情况:

$ <MTA_HOME>/mta-cli analyze --input /path/to/jee-example-app-1.0.0.ear \
    --output /path/to/report-output/ \
    --target eap7

2.2.2. 使用命令行执行分析

分析 允许使用 分析器-lsp 运行源代码和二进制分析。

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

mta-cli analyze --input=<path/to/source/code> --output=<path/to/output/dir>

所有标记:

Analyze application source code

Usage:
  mta-cli analyze [flags]

Flags:
      --analyze-known-libraries   analyze known open-source libraries
  -h, --help                      help for analyze
  -i, --input string              path to application source code or a binary
      --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 a 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")
  -o, --output string             path to the directory for analysis output
      --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

使用示例

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

    mta-cli analyze --list-targets
  3. 使用指定的目标技术运行分析,如 cloud-readiness

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

    $ ls ./output/ -1
    analysis.log
    dependencies.yaml
    dependency.log
    output.yaml
    static-report

output.yaml 是包含问题报告的文件。

static-report 包含静态 HTML 报告。

dependencies.yaml 包含依赖项报告。

2.2.3. 使用命令行执行转换

转换有两个子命令 - 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 cleanup temporary resources

Use "mta-cli transform [command] --help" for more information about a command.

2.2.3.1. OpenRewrite

openrewrite sub 命令允许在源代码上运行 OpenRewrite recipes。

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 cleanup temporary resources

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

mta-cli transform openrewrite --input=<path/to/source/code> --target=<exactly_one_target_from_the_list>

注意

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

2.2.3.2. 规则

rules 子命令允许使用 windup-shim 将 mta XML 规则转换为分析器-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)

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

mta-cli transform rules --input=<path/to/xmlrules> --output=<path/to/output/dir>

使用示例

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

    mta-cli transform openrewrite --list-targets
  3. 在示例应用程序上运行方法。

    mta-cli transform openrewrite --input=<path-to/jakartaee-duke> --target=jakarta-imports

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

2.2.3.3. 可用的 OpenRewrite recipes

表 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 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

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

© 2024 Red Hat, Inc.