Package, upload, and register

Updated at:

After you develop and debug a Java program, package it into a JAR file, upload the file as a resource to a MaxCompute project, and register it as a MaxCompute user-defined function (UDF) so that you can call it in Data Development. MaxCompute Studio lets you complete all three steps with a single click.

Prerequisites

The Java program is developed and debugged. For more information, see Develop UDFs, Develop MapReduce, or Develop Graph.

Feature description

MaxCompute Studio lets you package a Java program into a JAR file, upload the file to MaxCompute, and register a UDF with a single click. This is the recommended method.

Alternatively, you can perform the following three operations in MaxCompute Studio:

  1. Package the Java program into a JAR file. For more information, see Generate a JAR file.

  2. Upload the JAR file to MaxCompute. For more information, see Add resources.

  3. Register the MaxCompute UDF. For more information, see Register functions.

Procedure

  1. In IntelliJ IDEA, click Project in the navigation pane on the left. Go to the module's source folder, which is src > main > java. Right-click the compiled Java program and select Deploy to server….

  2. In the Package a jar, submit resource and register function dialog box, configure the parameters.

    Parameter name

    Description

    MaxCompute Project

    The destination MaxCompute project. Defaults to the project where the Java program is located.

    Resource file

    The local path of the JAR file after MaxCompute Studio packages the Java program.

    Resource name

    The resource name assigned to the JAR file in the MaxCompute project.

    Resource comment

    The comment for the JAR resource.

    Extra resources

    Other resource files that the MaxCompute UDF requires for registration. In the resource list, click the target resource files. To select multiple files, hold down the Ctrl key and click each file. The list shows resources that are already uploaded to your MaxCompute project. For more information about adding resources, see Add resources.

    Main class

    The class defined in your Java program for the new UDF.

    Function name

    The name used to call this UDF in SQL statements.

    Force update if already exists

    Overrides any existing function or resource with the same name in the MaxCompute project.

  3. Click OK to package the program, upload the resource, and register the MaxCompute UDF.

    After you complete these steps, you can call the UDF in SQL statements.

What to do next

After you register the Java UDF, you can call it using MaxCompute SQL:

  • Call the UDF from the project where it is registered: Use the UDF the same way you call a built-in function.

  • Call the UDF from another project: For example, call a UDF registered in project B from project A. SELECT B:<udf_name> (<arg0>, <arg1>) FROM <table_name>;. For more information about cross-project sharing, see Access resources across projects using packages.

References