IntelliJ를 사용하여 맞춤형 패키지 생성 및 구축
IntelliJ를 사용하여 Automation 360에서 Control Room에 패키지로 업로드할 수 있는 JAR 파일을 컴파일합니다.
전제 조건
작업 패키지를 구축하려면 JDK 및 Java IntelliJ에 대한 기본적인 이해가 필요합니다. 다음 소프트웨어와 파일이 필요합니다.
- Java SE 개발 키트 11개 다운로드
- Java IDE IntelliJ Community Edition
- Automation Anywhere A2019 SDK. 필요한 릴리즈의 zip 파일을 다운로드하여 압축을 풉니다. Enterprise A2019 패키지 개발 키트 릴리스 노트
프로시저
-
SDK 패키지의 내용을 IdeaProjects 디렉토리에 압축 해제하고, 폴더 이름을 A2019.10-package-sdk-1.0.0에서 MetricToImperial로 변경합니다.
기본적으로 패키지는 다음 위치에 있습니다. C:\Users\<User>\IdeaProjects.
- IntelliJ IDEA에서 파일 > 열기로 이동하여 C:\Users\<User>\IdeaProjects\MetricToImperial에서 프로젝트를 엽니다.
-
프로젝트 루트에서 settings.gradle 파일을 엽니다.
rootProject.name = 'MetricToImperial'
으로 설정합니다. - src > main > resources > package.template 위치의 package.template 파일을 업데이트합니다.
- 패키지 이름을 A2019DemoPackage에서 MetricToImperial로 변경합니다.
-
locales json에서 패키지 이름을 업데이트합니다. src > main > resources > locales > en_US.json으로 이동합니다.
-
en_US.json 파일을 열고 필요한 라벨 필드를 업데이트합니다. 선택적 설명을 업데이트합니다.
원본 en_US.json 업데이트된 en_US.json { "label" : "A2019DemoPackage", "description" : "Provides actions for A2019DemoPackage operations." }
{ "label" : "Metric To Imperial", "description" : "Converts lengths and distances from Metric format to Imperial format" }
- en_US.json 파일의 나머지 모든 줄을 삭제합니다.
-
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 클래스를 엽니다. 클래스 정의문 위에 다음 코드를 복사하여 붙여넣습니다.
-
src > main > resources > locales > 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 주석을 업데이트합니다.
-
프로젝트 루트에서 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를 입력하거나 Gradle 소스 세트에서 test\java 제안을 선택합니다.
- java 디렉토리를 마우스 오른쪽 버튼으로 클릭하고 새 > 패키지를 선택합니다.
- 새로 생성된 패키지의 이름을 com.automationanywhere.botcommand.metrictoimperial.commands로 입력합니다.
- 새 패키지를 마우스 오른쪽 버튼으로 클릭하고 새 > 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%\IdeaProjects\MetricToImperial"를 입력합니다.
- 프로젝트를 구축하려면 다음 명령어를 입력합니다. gradlew.bat clean build shadowJar
BUILD SUCCESSFUL(구축 성공) 메시지가 나타납니다.기존 파일을 자동으로 삭제할 수 없으면 구축에 실패할 수 있으며 태스크 실행이 실패했음을 나타내는 clean이라는 시스템 메시지가 표시됩니다. 이 경우 탐색기 창을 닫고 구축을 다시 실행하십시오.