2 years ago
#43360
Ameya Joshi
Java Stack Trace: java.lang.NoClassDefFoundError: scala/collection/Seq while trying to run jar having class for Snowflake account connection
I have written Scala class which is showing tables from one of the Snowflake database. I have imported com.snowflake.snowpark._ & com.snowflake.snowpark.functions._ libraries. When I do sbt compile & sbt run, I am able to see database tables as output.
.jar file gets generated in <>project-folder>\target\scala-2.12
When I try to run this .jar using scala, I get error as java.lang.NoClassDefFoundError: scala/collection/Seq but when I run simple helloworld.jar as "scala helloworld.jar" --> it runs properly & display the output
Here is my class in scala program:
class Weather{
def disp(){
// Replace the <placeholders> below.
val configs = Map (
"URL" -> "https://<*****>.snowflakecomputing.com:443",
"USER" -> "<*****>",
"PASSWORD" -> "<******>",
"ROLE" -> "<*****>",
"WAREHOUSE" -> "<*****>",
"DB" -> "SNOWFLAKE_SAMPLE_DATA",
"SCHEMA" -> "WEATHER"
)
val session = Session.builder.configs(configs).create
session.sql("show tables").show()
}
}
I need to use this jar in Snowflake UDF like below:
CREATE OR REPLACE FUNCTION Weather_Tables()
RETURNS NUMBER
LANGUAGE JAVA
IMPORTS = ('@snowpark_stage/snowflake_connection_12jan_2.12-1.0.jar')
HANDLER = 'Weather.disp';
my build.sbt file content:
scalaVersion := "2.12.11"
//scalaVersion := "2.11"
// That is, to create a valid sbt build, all you've got to do is define the
// version of Scala you'd like your project to use.
// ============================================================================
// Lines like the above defining `scalaVersion` are called "settings". Settings
// are key/value pairs. In the case of `scalaVersion`, the key is "scalaVersion"
// and the value is "2.13.3"
// It's possible to define many kinds of settings, such as:
name := "snowflake_connection_12jan"
organization := "ch.epfl.scala"
version := "1.0"
// Note, it's not required for you to define these three settings. These are
// mostly only necessary if you intend to publish your library's binaries on a
// place like Sonatype.
// Want to use a published library in your project?
// You can define other libraries as dependencies in your build like this:
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"
resolvers += "OSGeo Release Repository" at "https://repo.osgeo.org/repository/release/"
libraryDependencies += "com.snowflake" % "snowpark" % "0.11.0"
//libraryDependencies += "com.snowflake" % "snowpark" % "0.6.0"
libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.2.0"
// unmanagedClasspath/includeFilter := "lib"
// Here, `libraryDependencies` is a set of dependencies, and by using `+=`,
// we're adding the scala-parser-combinators dependency to the set of dependencies
// that sbt will go and fetch when it starts up.
// Now, in any Scala file, you can import classes, objects, etc., from
// scala-parser-combinators with a regular import.
Compile/console/scalacOptions += "-Yrepl-class-based"
Compile/console/scalacOptions += "-Yrepl-outdir"
Compile/console/scalacOptions += "repl_classes"
Please guide me if anyone know how to solve this error.
java
scala
snowflake-cloud-data-platform
noclassdeffounderror
0 Answers
Your Answer