简体   繁体   中英

Exception in thread "main" java.lang.NoClassDefFoundError: org/rogach/scallop/ScallopConf

As I want to execute the jar generated by my scala project in the Command Line Interface, I get the following problem: Exception in thread "main" java.lang.NoClassDefFoundError: org/rogach/scallop/ScallopConf

Although in the dependency file I mentionned scallop dependency as follow

import sbt._

object Dependencies {
  lazy val betterFiles = "com.github.pathikrit" %% "better-files" %  "3.7.0"
  lazy val scalaz = "org.scalaz" %% "scalaz-core" % "7.2.27"
  lazy val scallop = "org.rogach" %% "scallop" % "3.1.5"

  // -- Logging
  lazy val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"
  lazy val slf4jBackend = "org.slf4j" % "slf4j-simple" % "1.7.26"

  // -- Testing
  lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
}

My build.sbt file is the following:

import Dependencies._

ThisBuild / scalaVersion     := "2.12.5"
ThisBuild / sbtVersion       := "1.2.6"
ThisBuild / version          := "0.1.0-SNAPSHOT"

lazy val root = (project in file("."))
  .settings(
    name := "phenix-challenge",
    libraryDependencies ++= Seq(
      betterFiles,
      scalaz,
      scallop,

      scalaLogging,
      slf4jBackend % Runtime,

      scalaTest % Test
    )
  )

If you have an Idea that could resolve my Issue please HELP!

Many thanks in advance

To execute the jar generated by your scala project in the Command Line Interface you can use sbt plugin to assembly a fat-jar including your libraries/dependencies. Having such jar you would be able to run your app via java -jar ...

There are several SBT plugins for build a fat-jar. Perhaps the easiest one would be the sbt-assembly.

  1. Add this plugin to file project/plugins.sbt (create this file if needed): addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
  2. Now use sbt to build a fat-jar:
sbt assembly
  1. Then run via java -jar YouMainClass

Another option is to use pure sbt to run Main class using command sbt run , then you do really need to build a fat-jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM