Packaging Java or Scala Handler Code with Maven¶
If you are using Maven to build and package your code, you can use the Maven Assembly Plugin to create a JAR file that contains all of the dependencies.
Once you have a JAR file, you can upload the file to a Snowflake stage, then reference it in an IMPORTS statement when you create a function or procedure. For more information on uploading JAR files, refer to Making dependencies available to your code. For more information on choosing whether to have code inline or on a stage, refer to Keeping handler code in-line or on a stage.
To create an JAR file with your handler code, use the following steps.
In the directory for your project (for example,
hello-snowpark/), create a subdirectory namedassembly/.In that directory, create an assembly descriptor file that specifies that you want to include dependencies in your JAR file.
For an example, see jar-with-dependencies.
If your project requires the Snowpark library, exclude its JAR file from the output archive because the library is already included on Snowflake.
In the assembly descriptor, add a
<dependencySet>element that excludes the Snowpark library from your JAR file.For example:
For information about the elements in an assembly descriptor, see Assembly Descriptor Format.
In your
pom.xmlfile, under the<project>»<build>»<plugins>, add a<plugin>element for the Maven Assembly Plugin.In addition, under
<configuration>»<descriptors>, add a<descriptor>that points to the assembly descriptor file that you created in the previous steps.For example: