Package, upload, and register
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:
-
Package the Java program into a JAR file. For more information, see Generate a JAR file.
-
Upload the JAR file to MaxCompute. For more information, see Add resources.
-
Register the MaxCompute UDF. For more information, see Register functions.
Procedure
-
In IntelliJ IDEA, click Project in the navigation pane on the left. Go to the module's source folder, which is . Right-click the compiled Java program and select Deploy to server….
-
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.
-
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
-
For common issues when developing and calling Java UDFs, see FAQ for MaxCompute Java UDFs.
-
For UDF development examples, see UDF development examples.