Build a custom package in IntelliJ
- Updated: 2024/09/11
Build a custom package in IntelliJ
Use Java IntelliJ to create and compile a JAR file that you can upload as a package to your Control Room in Automation 360.
Prerequisites
A basic understanding of JDK and Java IntelliJ is required in order to build an action package. Ensure you have installed the following software and files:
Procedure
- Download the latest release of the Automation Anywhere Package SDK. For the latest release of the Package SDK, see - Previous Package SDK Release Notes.
- Unzip the contents of the SDK package to any of your local directory.
- Rename the folder from A360-package-sdk-<version number> to MetricToImperial.
-
In IntelliJ IDEA, go to File > Open and open the project at
C:\<SavedLocation>\MetricToImperial.
-
Open the settings.gradle file in the project root. Set the
rootProject.name = 'MetricToImperial'
- Open the package.template file located at src > main > resources > package.template.
-
Change the package name from A360DemoPackage to
MetricToImperial.
Click the Sync button in IntelliJ to update the project. -
Update the package name in locales json: go to src > main > resources > locales > en_US.json.
- Open the en_US.json file and update the required label field from A360DemoPackage to MetricToImperial. Update the optional description.
- Delete all other remaining lines in the en_US.json file.
- Delete the sample packages, go to src > main > java > com.automationanyhwere.botcommand, and delete the samples.commands and delete the samples packages.
- Create a new package, right-click on java folder and select New > Package. Enter the new package name as metrictoimperial.commands.
-
Create a new Java Class, right-click on the
metrictoimperial.commands package, and select New > Java Class. Enter the name for the new class
CMtoINCH:
-
Open the CMtoINCH class. Copy and paste the
following code above the class definition statement:
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)
- Inside the CMtoINCH class, copy and paste the following code:
//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); }
To import the namespaces, click the highlighted red notations and press ALT+ENTER key and select Import which automatically imports namespaces based on the annotations and datatypes.
-
Open the CMtoINCH class. Copy and paste the
following code above the class definition statement:
-
Configure en_US.json file, go to src > main > resources > locales > en_US.json and add the following fields after the label and description
values:
"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"
- Update the CommandPkg annotation. Download icons from Github.
-
Open the build.gradle in the project root. After the
dependencies section, but before the last closing tag, copy and paste the
following code:
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" }
-
Update the version number and remove dependencies that is not required for your
project from build.gradle.
Note: Custom package versions must adhere to the Semantic Versioning specification. A valid version consists of three numbers (
MAJOR.MINOR.PATCH
) separated by periods (.
). You can optionally include a pre-release identifier after thePATCH
version, separated by a hyphen (-
). Underscores (_
) are not allowed.Examples of valid package versions:
2.0.2-20210701-202149
2.0.2
2.0.2-test-20210701-202149
-
Create a new directory, right-click src and select New > Directory.
- In the Name field, enter test\java, or select the test\java suggestion from the Gradle Source Sets.
- Create a new package, right-click the java directory and select New > Package.
- Enter the name for the newly created package: metrictoimperial.commands.
-
Create new Java class, right-click and select New > Java Class. Enter the name for the new class
CMtoINCHTest.
Inside the CMtoINCHTest class, copy and paste the following code:
@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); }
- Save the project File > Save All.
-
Build the package.
You can use the IntelliJ UI or the command line. If you are using the command line:
- Open a terminal window and navigate to the MetricToImperial directory.
- To build the project, enter the following command: gradlew.bat clean build shadowJar
A BUILD SUCCESSFUL message appears.Sometimes a build might fail because existing files could not be automatically deleted and a system message appears indicating the execution failed for the task: clean. If this occurs, close the explorer windows and run the build again.