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

  1. Download the latest release of the Automation Anywhere Package SDK. For the latest release of the Package SDK, see - Previous Package SDK Release Notes.
  2. Unzip the contents of the SDK package to any of your local directory.
  3. Rename the folder from A360-package-sdk-<version number> to MetricToImperial.
  4. In IntelliJ IDEA, go to File > Open and open the project at C:\<SavedLocation>\MetricToImperial.
    IntelliJ File Open
  5. Open the settings.gradle file in the project root. Set the rootProject.name = 'MetricToImperial'
    Setting.gradle Project name
  6. Open the package.template file located at src > main > resources > package.template.
  7. Change the package name from A360DemoPackage to MetricToImperial.
    Rename the Package.Template name field
    Click the Sync button in IntelliJ to update the project.
  8. Update the package name in locales json: go to src > main > resources > locales > en_US.json.
    1. Open the en_US.json file and update the required label field from A360DemoPackage to MetricToImperial. Update the optional description.
    2. Delete all other remaining lines in the en_US.json file.
  9. Delete the sample packages, go to src > main > java > com.automationanyhwere.botcommand, and delete the samples.commands and delete the samples packages.
  10. Create a new package, right-click on java folder and select New > Package. Enter the new package name as metrictoimperial.commands.
  11. 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:
    1. 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)
    2. 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.
    CMtoINCH Java Class
  12. 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"

    Configure en_US.json
  13. Update the CommandPkg annotation. Download icons from Github.
    1. Download ruler_icon.svg from github and right-click the image and save the image as ruler_icon.svg.
    2. Download iconwhite.svg from github, right-click the image and save the image iconwhite.svg.
    3. Copy both files into the src > main > resources > icons folder.
      Icons for Pod
  14. 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"
    }
  15. Update the version number and remove dependencies that is not required for your project from build.gradle.
  16. Create a new directory, right-click src and select New > Directory.
    1. In the Name field, enter test\java, or select the test\java suggestion from the Gradle Source Sets.
    2. Create a new package, right-click the java directory and select New > Package.
    3. Enter the name for the newly created package: metrictoimperial.commands.
  17. 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);
    }

    CM to INCH Test class
  18. Save the project File > Save All.
  19. Build the package.
    You can use the IntelliJ UI or the command line. If you are using the command line:
    1. Open a terminal window and navigate to the MetricToImperial directory.
    2. 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.

Next steps

Add custom package to your Control Room