使用 Java IntelliJ 创建并编译一个 JAR 文件,您可以将其作为包上传至 Automation 360Control Room

先决条件

要构建一个操作包,需要对 JDK 和 Java IntelliJ 有基本了解。 确保您已安装以下软件和文件:

过程

  1. 下载最新版本的 Automation Anywhere SDK 包。 有关 SDK 包的最新版本,请参阅 - 既往软件开发工具包 (SDK) 发行说明
  2. 将 SDK 包的内容解压到本地目录中的任意位置。
  3. 将文件夹从 A360-package-sdk-<version number> 重命名为 MetricToImperial
  4. 在 IntelliJ IDEA 中,前往 文件 > 打开 并打开位于 C:\<SavedLocation>\MetricToImperial 的项目。
    IntelliJ 文件打开
  5. 在项目根目录中打开 settings.gradle 文件。 设置 rootProject.name = 'MetricToImperial'
    Setting.gradle 项目名称
  6. 打开位于 src > main > resources > package.templatepackage.template 文件。
  7. 将包名称从 A360DemoPackage 更改为 MetricToImperial
    重命名 Package.Template 名称字段
    单击 IntelliJ 中的同步按钮以更新项目。
  8. 更新 locales json 中的包名称:前往 src > main > resources > locales > en_US.json
    1. 打开 en_US.json 文件,并将 required label 字段从 A360DemoPackage 更新为 MetricToImperial。 更新可选描述
    2. 删除 en_US.json 文件中其余的所有行。
  9. 删除示例包,前往 src > main > java > com.automationanyhwere.botcommand,并删除 samples.commandssamples 包。
  10. 创建一个新包,右键单击 java 文件夹,然后选择 新建 > 。 输入新包名称为 metrictoimperial.commands
  11. 创建新的 Java 类,右键单击 metrictoimperial.commands 包,然后选择 新建 > Java 类。 输入新建类的名称为 CMtoINCH:
    1. 打开 CMtoINCH 类。 在类别定义叙述上方复制并粘贴以下代码:
      import static com.automationanywhere.commandsdk.model.DataType.NUMBER; //BotCommand makes a class eligible for being considered as an action. @BotCommand //CommandPks adds required information to be dispalable on GUI. @CommandPkg( //Unique name inside a package and label to display. name = "CMtoInch", label = "[[CMtoINCH.label]]", node_label = "[[CMtoINCH.node_label]]", description = "[[CMtoINCH.description]]", icon = "ruler_icon.svg", //Return type information. return_type ensures only the right kind of variable is provided on the UI. return_label = "[[CMtoINCH.return_label]]", return_type = NUMBER, return_required = true)
    2. CMtoINCH 类中,复制并粘贴以下代码:
    //Identify the entry point for the action. Returns a Value<String> because the return type is String. @Execute public NumberValue action( //Idx 1 would be displayed first, with a text box for entering the value. @Idx(index = "1", type = AttributeType.NUMBER) //UI labels. @Pkg(label = "[[CMtoINCH.CMInput.label]]") //Ensure that a validation error is thrown when the value is null. @NotEmpty Double CMInput) { //Internal validation, to disallow empty inputs. No null check needed as we have NotEmpty on CMInput. if ("".equals(CMInput.toString().trim())) throw new BotCommandException("Input of CM is required"); Number result; try { //Conversion logic result = CMInput * 0.393701; } catch (Exception e) { //Throw custom error message throw new BotCommandException("Unable to convert " + CMInput.toString() + "cm to inches"); } //Return NumberValue. return new NumberValue(result); }
    要导入命名空间,请单击高亮显示的红色标注,然后按下 ALT+ENTER 键并选择导入,这将根据注释和数据类型自动导入命名空间
    CMtoINCH Java 类
  12. 配置 en_US.json 文件,前往 src > main > resources > locales > en_US.json,并在标签和描述值后添加以下字段:
    "CMtoINCH.label" : "厘米到英寸", "CMtoINCH.node_label": "厘米到英寸", "CMtoINCH.description" : "将厘米转换为英寸", "CMtoINCH.return_label" : "将输出的英寸分配给一个数字变量", "CMtoINCH.CMInput.label" : "要转换为英寸的厘米"

    配置 en_US.json
  13. 更新 CommandPkg 注释。 从 Github 下载图标。
    1. ruler_icon.svg 下载 github,右键单击图像并将图像保存为 ruler_icon.svg
    2. iconwhite.svg 下载 github,右键单击图像并保存图像 iconwhite.svg
    3. 将这两个文件都复制到 src > main > resources > icons 文件夹。
      Pod 的图标
  14. 在项目根目录中打开 build.gradle。 在依赖项部分之后,但在最后一个结束标签之前,复制并粘贴以下代码:
    test { testLogging { exceptionFormat = 'full' } useTestNG() {} afterSuite { desc, result -> if (!desc.parent) println("${result.resultType} " + "(${result.testCount} tests, " + "${result.successfulTestCount} successes, " + "${result.failedTestCount} failures, " + "${result.skippedTestCount} skipped)") } maxHeapSize "3g" }
  15. 更新版本号,并从 build.gradle 中移除项目不需要的依赖项。
    注: 自定义包版本必须遵循 语义版本控制 规范。 有效的版本由三个数字 (MAJOR.MINOR.PATCH) 组成,数字之间用句点 (.) 分隔。 您可以在 PATCH 版本后选择性地添加一个预发布标识符,用连字符 (-) 分隔。 不允许使用下划线 (_)。

    有效包版本的示例:

    • 2.0.2-20210701-202149
    • 2.0.2
    • 2.0.2-test-20210701-202149
  16. 创建一个新目录,右键单击 src 并选择 新建 > 目录
    1. 名称字段中,输入 test\java,或从 Gradle 源集中选择 test\java 建议。
    2. 创建一个新包,右键单击 java 目录,然后选择 新建 >
    3. 输入新创建包的名称:metrictoimperial.commands
  17. 创建新的 Java 类,右键单击并选择 新建 > Java 类。 输入新建类 CMtoINCHTest的名称。
    CMtoINCHTest 类中,复制并粘贴以下代码:
    @Test public void testCMtoINCH(){ Double validInput = 10.00; Double expectedOutput = 0.393701 * validInput; CMtoINCH testCM = new CMtoINCH(); Value<Double> result = testCM.action(validInput); Assert.assertEquals(result.get(), expectedOutput); }

    厘米到英寸测试类
  18. 保存项目文件 > 全部保存
  19. 构建包。
    您可以使用 IntelliJ UI 或命令行。 如果您正在使用命令行:
    1. 打开终端窗口并导航到 MetricToImperial 目录。
    2. 要构建项目,请输入以下命令:gradlew.bat clean build shadowJar
    将显示构建成功的消息。

    有时,由于无法自动删除现有文件会导致构建失败,并显示一条系统消息,指出任务执行失败:清除。 如果发生这种情况,请关闭资源管理器窗口并再次运行“构建”。

后续步骤

将自定义软件包添加到您的 Control Room