使用 IntelliJ 建立並建立自訂套件
使用 Java IntelliJ 編譯 JAR 文件,您可以將其作爲軟件包上載到 Control Room 中。 Automation 360
先決條件
要構建操作包,需要基本瞭解 JDK 和 Java IntelliJ 。確保以下軟件和文件:
- Java SE Development Kit 11 下載
- IntelliJ 的 Java IDE Community 版本
- Automation Anywhere A2019 SDK 。下載並解壓縮所需版本的 zip 文件:企業 A2019 套件開發套件版本說明
程序
-
將 SDK 軟件包的內容解壓縮到 IdeaProbest 目錄,並將該文件夾從 A209-package-SDK-< 版本號 > 重命名 爲 MetricToImperial。
默認情況下,軟件包位於:C:\Users\<User>\IdeaProObjects。
- 在 IntelliJ Idea 中,轉到 File > Open (文件打開),然後在 C:\Users\<User>\IdeaProObjects\MetricToImperial ( C:\Users\<User>\IdeaProObjects\MetricToImperial)打開項目。
-
在 項目根目錄中打開 settings.gradle 文件。設置
rootProject.name = 'MetricToImperial '
- 更新 位於 src > 主 > 資源 > package.template 的 package.template 文件。
- 將軟件包名稱從 A2019 DemoPackage 更改爲 MetricToImperial。
-
更新 語言環境 json 中的軟件包名稱:轉至 src > 主 > 資源 > 語言環境 > en_US.json。
- 打開 en_US.json 文件,並將 所需 標籤 字段從 A2019 DemoPackage 更新爲 MetricToImperial。更新可選 說明。
- 刪除 en_US.json 文件中的所有其他行。
-
創建新 的 Java 類,右鍵單擊 metrictoimperial.commands 包,然後選擇 “新建 > Java 類”。輸入新類 CMtoINCH 的名稱:
-
打開 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 = "CM to Inch", 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)
- 在 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 類。將以下代碼複製並粘貼到類定義語句的上方:
-
配置 en_US.json 文件,轉至 src > 主 > 資源 > 區域 > 設置 en_US.json ,並在標籤和說明值之後添加以下字段:
"CMtoINCH.label" : "cm to inches", "CMtoINCH.node_label": "cm to inches", "CMtoINCH.description" : "Convert centimeters to inches", "CMtoINCH.return_label" : "Assign the Output in Inches to a Number Variable", "CMtoINCH.CMInput.label" : "Centimeters to Convert to Inches"
- 刪除示例軟件包,轉至 src > main > Java > com.automationanyhwere.botcommand,然後刪除 samples.commands 並刪除 樣例 軟件包。
-
更新 CommandPkg 註釋。從 Github 下載圖標。
- 從 GitHub 下載標尺 _icon.svg ,然後右鍵單擊圖像並將圖像保存爲 標尺 _icon.svg。
- 從 GitHub 下載 iconwhit.svg,右鍵單擊圖像並保存圖像 iconwhit.svg。
- 將兩個文件複製到 src > 主 > 資源 > 圖標 文件夾中。
-
在 項目根目錄中打開 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" }
-
創建新目錄,右鍵單擊 src ,然後選擇 新建 > 目錄。
- 在“名稱”字段中,輸入 test\java,或從 “ Gral度 源集”中選擇 test\java 建議。
- 創建新軟件包,右鍵單擊 Java 目錄並選擇 新建 > 軟件包。
- 輸入新創建的軟件包的名稱: com.automationanywhere.botcommand.metrictoimperial.commands。
-
創建新的 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); }
- 保存項目 文件 > 保存全部。
-
構建軟件包。
您可以使用 IntelliJ UI 或命令列。如果使用的是命令行:
- 打開終端窗口,導航至 MetricToImperial 目錄並輸入: cd "%USERPROFILE%\IdeaProObjects\MetricToImperial "
- 要生成項目,請輸入以下命令: gradlew.bat clean build shadowJar
出現“ build successful (生成成功)”信息。有時,生成可能會失敗,因爲無法自動刪除現有文件,並且會出現一條系統消息,指示任務 的執行失敗: Clean。如果發生這種情況,請關閉資源管理器窗口並再次運行生成。