Scala/Spark/Databricks: How to import code from user-created JAR? - scala

I have a JAR that I created with intellij and sbt, that defines a case class and Object. I've uploaded it to my databricks workspace, and attached it to a cluster as a library.
How do I actually import code from it/reference it in my notebook? So far all I can think of is to try
import NameOfJar._
which gives
java.lang.NoClassDefFoundError: DataFrameComparison$
Do I need to have built the jar differently somehow? (Package statement or something?)

you should import import packageName._, jar name is not used in import statement. It should work the same as in usual local java/scala code.
You can check this article for details - https://docs.databricks.com/libraries.html
Btw, does your notebook fail on import itself, or later, when you're trying to use class, that exists inside jar?

Related

Reference uploaded JAR library

I've billed set of support function into helper.jar library and imported to Databricks cluster. The jar is installed on the cluster, but I'm not able to reference the functions in the library.
The jar import has been tested, cluster restarted and the jar can be referenced in InelliJ where it was developed as Azure Spark/HDInsight project.
//next line generates error value helper is not a member of org.apache.spark.sql.SparkSession
import helper
//nex line generates error: not found: value fn_conversion
display(df.withColumn("RevenueConstantUSD", fn_conversion($"Revenue"))
I'd expect the helper function would be visible after library deployment or possibly after adding the import command.
Edit: added information about IntelliJ project type

Can't import Jena classes

I'm setting up Jena in eclipse. However, when I try to import any class, such as the Model class, I am getting the error "The import com.hp cannot be resolved". I already set up the build path to the Jena library. Below is a picture of my simple setup and as you can see I am getting an error on the import statement.
http://imgur.com/Z1tfF5f
The package tree starts org.apache.jena for Jena version 3 onwards. Your IDE can help by finding the class Model

Cannot import external JAVA library using Jython in Eclipse

I'm new to Jython and to Eclipse. I'm trying to use the JGraphX JAVA library. I've created a new PyDev project and package. I've right-clicked on the project properties in Eclipse, selected "PyDev - PYTHONPATH" and added jgraphx.jar. In the init.py file, I've tried:
import jgraphx as jgx
from jgraphx import *
Neither approach works. The code is underlined as an error in Eclipse. When I run, I get "ImportError: No module named jgraphx". What am I doing wrong?
Thank you,
-david
I'm not familiar with the JGraphX library.
To import a java class
you need to use from my.project.package import someclass

org.apache.commons.codec Cannot be resolved

I'm trying to import org.apache.commons.codec.binary.Base64.encodeBase64, but Eclipse keeps telling me this import cannot be resolved, even though I've added the apache commons codec jar file to both the lib file of my project and also as an Eclipse plugin. What could be causing this issue?
org.apache.commons.codec.binary.Base64.encodeBase64 is a method. You import Types, like org.apache.commons.codec.binary.Base64.

Cannot import Appengine modules in Eclipse

In my Eclipse project (GWT) I am trying to import the modules below, in order to add some Blobstore code.
import com.google.appengine.api.files.FileService;
import com.google.appengine.api.files.FileServiceFactory;
I don't get any error or warning from the Eclipse build function. Nevertheless, when I do "GWT compile" from Eclipse, I get the error messages below:
[ERROR] Line 3: The import com.google.appengine.api.files cannot be resolved
[ERROR] Line 4: The import com.google.appengine.api.files cannot be resolved
How can I sort it out? Thanks!
You cannot reference non-client code from your GWT client. Remember that your GWT client code will be compiled to Javascript, so any references to actual Java can't be compiled out.
Make sure any reference to the blobstore api is done in server code, not client. Those imports should never be necessary in code that must be compilable to javascript.