Package, upload, and register

更新时间:
复制 MD 格式

After you develop and debug a Java program, you must 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). You can then call the UDF in Data Development. This topic describes how to package a Java program, upload the JAR file, and register the UDF with a single click in MaxCompute Studio.

Prerequisites

The Java program has been developed and debugged. For more information about how to develop and debug Java programs, 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 MaxCompute 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 name of the destination MaxCompute project. This field automatically shows the project where the Java program is located. You do not need to select a project from the drop-down list.

    Resource file

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

    Resource name

    The name of the resource after the JAR file is uploaded to 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 name for the new MaxCompute UDF. This is the class defined in your Java program.

    Function name

    The name of the MaxCompute UDF that is registered from the JAR resource. This is the name you will use to call the function in SQL.

    Force update if already exists

    Select this option to override an existing function or resource in the MaxCompute project that has the same name.

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

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

What to do next

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

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

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

References