1
votes

I have defined project dependencies and merge strategies for them to generate the jar file with the sbt-assembly plugin. Alos, the main class in the future jar was defined too. After I create the jar file and try to run it using the bash script I get an error:

Error: Could not find or load main class benchmarks.Main

Main is in src/main/scala/benchmarks/Main and it is an object with the main method. What may be the problem in this project?

Here is my bash script:

#!/usr/bin/env bash
java -cp "target/scala-2.11/benchmarking.jar" benchmarks.Main $1 $2

build.sbt with defined dependencies:

version := "0.1"

scalaVersion := "2.11.8"

assemblyJarName in assembly := "benchmarking.jar"

mainClass in assembly := Some("benchmarks.Main")

val sparkVersion = "2.2.0"

resolvers += "Spark Packages Repo" at "http://dl.bintray.com/spark-packages/maven"
libraryDependencies ++= Seq(
  "neo4j-contrib" % "neo4j-spark-connector" % "2.1.0-M4",
  "org.apache.spark" %% "spark-core" % sparkVersion % "provided",
  "org.apache.spark" %% "spark-sql" % sparkVersion  % "provided",
  "com.typesafe" % "config" % "1.3.0",
  "org.neo4j.driver" % "neo4j-java-driver" % "1.5.1",
  "com.opencsv" % "opencsv" % "4.1",
  "com.databricks" %% "spark-csv" % "1.5.0"
)

assemblyMergeStrategy in assembly := {
  case PathList("org","aopalliance", xs @ _*) => MergeStrategy.last
  case PathList("javax", "inject", xs @ _*) => MergeStrategy.last
  case PathList("javax", "servlet", xs @ _*) => MergeStrategy.last
  case PathList("javax", "activation", xs @ _*) => MergeStrategy.last
  case PathList("org", "apache", xs @ _*) => MergeStrategy.last
  case PathList("com", "google", xs @ _*) => MergeStrategy.last
  case PathList("com", "esotericsoftware", xs @ _*) => MergeStrategy.last
  case PathList("com", "codahale", xs @ _*) => MergeStrategy.last
  case PathList("com", "yammer", xs @ _*) => MergeStrategy.last
  case PathList("com", "typesafe", xs @ _*) => MergeStrategy.last
  case PathList("net", "jpountz", xs @ _*) => MergeStrategy.last
  case PathList("org", "slf4j", xs @ _*) => MergeStrategy.last
  case PathList("org", "neo4j", xs @ _*) => MergeStrategy.last
  case "about.html" => MergeStrategy.rename
  case "META-INF/ECLIPSEF.RSA" => MergeStrategy.last
  case "META-INF/mailcap" => MergeStrategy.last
  case "META-INF/mimetypes.default" => MergeStrategy.last
  case "plugin.properties" => MergeStrategy.last
  case "log4j.properties" => MergeStrategy.last
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
      oldStrategy(x)
}
1

1 Answers

0
votes

Rebuilding new jar and checking main class location worked.