scala & intellij : difficulties to create a runnnable jar

2.2k views Asked by At

I can't launch a scala jar; when I launch it I get the error "Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/immutable/List" which seems to mean the scala library is not loaded...

enter image description here

this is a screenshot showing a lot of informations on the artifact window. here is the manifest:


Manifest-Version: 1.0 Class-Path: libs/scala-library-2.10.0.jar libs/commons-logging-1.1.1.j ar libs/jcip-annotations-1.0.jar libs/jwnl-1.4_rc3.jar libs/laf-plugi n-7.2.1.jar libs/laf-widget-7.2.1.jar libs/miglayout-core-4.2.jar lib s/miglayout-swing-4.2.jar libs/scala-actors.jar libs/scala-library.ja r libs/scala-swing.jar libs/slf4j-api-1.6.4.jar libs/slick_2.10-1.0.0 .jar libs/sqlite-jdbc-3.7.2.jar libs/substance-7.2.1.jar libs/trident -7.2.1-swing.jar Main-Class: Fenetre


and when I enter "java xf myJar.jar", there are extracted files in the directory: - .class files - in the libs folder, there are the libraries INCLUDING scala-library.jar & scala-library-2.10.0.jar(I specified only one of these two files in the manifest to avoid conflicts)

can you help me?

2

There are 2 answers

0
Sean Glover On

Despite what your manifest is telling you, when you run the application you either do not have the scala-library included in your class path or there's some confusion when you attempt to import List. Scala should automatically import the immutable collection classes in your project with the root Predef implementation.

Predef provides type aliases for types which are commonly used, such as the immutable collection types scala.collection.immutable.Map, scala.collection.immutable.Set, and the scala.collection.immutable.List constructors (scala.collection.immutable.:: and scala.collection.immutable.Nil). The types Pair (a scala.Tuple2) and Triple (a scala.Tuple3), with simple constructors, are also provided.

Predef in core Scaladocs

Try printing the classpath from within your app to confirm.

Although not pertinent to your question, I would recommend using SBT for dependency management now that IntelliJ IDEA 13 has full SBT integration support. Your collaborators not using IntelliJ will also be happier because SBT gives them more options for build technologies, editors, and other tooling when working on the project.

3
user3083520 On

I'm new to Scala and don't know what the problem is however I've been compiling "fat jars" which include all the required libs.

I've been using https://github.com/sbt/sbt-assembly to do this successfully.