Add JARs to Livy Sessions
Describes how to make additional JAR files available to Spark sessions submitted through Livy, either on a per-session basis or as defaults for all sessions.
About this task
When you submit Spark jobs through the Livy REST server, the process for managing JAR
dependencies works differently than with spark-submit. In
particular:
-
Livy always overrides the
spark.jarssetting fromspark-defaults.confwith its own value, populated from thelivy.repl.jarsproperty inlivy.conf. This ensures that the JARs required to run the Livy session application are deployed. -
Therefore, setting
spark.jarsinspark-defaults.confhas no effect on Livy sessions.You can add JARs to Livy sessions using either of the following approaches.
Adding JARs to a specific Livy session
Use this method when individual sessions require specific JAR files.
- Upload the JAR files to a location on the MapR file system.
- When creating a Livy session, specify the JARs using the
jarsoption in the POST /sessions request body. Thejarsoption maps directly to thespark.jarsSpark property. For example:{ "kind": "spark", "jars": [ "/user/myuser/jars/custom-lib.jar", "/user/myuser/jars/delta-spark_2.12-3.3.2.jar" ] }IMPORTANT- The default URI scheme for the
jarsoption ismaprfs:///. When a file path has no URI scheme, Livy uses thefs.defaultFSHadoop property as the default. On Data Fabric clusters, this property is set tomaprfs:///. -
-
The
file:///scheme is not allowed in thejarsoption. In Spark,file:///refers to the local file system of the machine runningspark-submit. This does not apply to Livy, where sessions are submitted over HTTP — the Livy server has no access to the client's local file system.
-
- The default URI scheme for the
Adding default JARs to all Livy sessions
Use one of the following methods when you need specific JARs available to every Livy session.
- Copy the JAR files into the following directory on every node where the Livy
server
runs:
/opt/mapr/livy/livy-<version>/repl_<scala_version>-jars/Livy automatically includes all JARs in this directory when populating the default value of
livy.repl.jars. - Restart the Livy server for the changes to take effect.
Method 2: Set the livy.repl.jars property in
livy.conf
Use this method when you want explicit control over the list of JARs deployed to every session.
- Open
/opt/mapr/livy/livy-<version>/conf/livy.confin a text editor. - Add or update the
livy.repl.jarsproperty. You must list all standard Livy JARs explicitly in addition to your custom JARs. For example (shown for Livy from DEP 10.0.0):livy.repl.jars file:///path/to/custom.jar,file:///opt/mapr/livy/livy-0.8.0/repl_2.12-jars/commons-codec-1.9.jar,file:///opt/mapr/livy/livy-0.8.0/repl_2.12-jars/livy-core_2.12-0.8.0.200-dep-1000.jar,file:///opt/mapr/livy/livy-0.8.0/repl_2.12-jars/livy-repl_2.12-0.8.0.200-dep-1000.jarIMPORTANTIf you omit any of the standard Livy JARs from this list, Livy sessions will fail to start. List the full contents of therepl_<scala_version>-jarsdirectory along with your custom JARs. - Restart the Livy server for the changes to take effect.