1

I'm working on eclipse with Scala 2.9.3 plugin installed.
I have a Scala project which work fine from the eclipse but when I export the project to "Runnable JAR File" and I try to run it I'm getting the following exception:

java.lang.NoClassDefFoundError: scala/ScalaObject

I tried all the 3 Library handling options:

  • Extract required libraries...
  • Package required libraries...
  • Copy required libraries...

All end up in the same exception.

What I need to do in order to make a standalone JAR file from my project?

Roee Gavirel
  • 18,955
  • 12
  • 67
  • 94

2 Answers2

1

I've used sbt-assembly plugin in the past, I found it quite easy to use.

pedrofurla
  • 12,763
  • 1
  • 38
  • 49
1

If you are using SBT for maintaining & building your project, then like pedrofurla suggested you should try sbt-assembly plugin. In the simplest case just add the follwing to your project build (i prefer Build.scala, but in *.sbt it looks the same):

1) imports:

import sbtassembly.Plugin._
import AssemblyKeys._

2) settings:

mainClass in assembly := Some("path.to.MainClass")
jarName   in assembly := "jar-name.jar"

3) If you want to publish artifact:

artifact in (Compile, assembly) ~= { art =>
  art.copy(`classifier` = Some("assembly"))
} // add classifier

and then your publishing task:

lazy val publishingSettings = addArtifact(artifact in (Compile, assembly), assembly) ++ Seq(
    publishTo := /* your repository settings */
  )

The call assembly to get all-in-one jar-file or publish to publish it to your repo. That should work

4lex1v
  • 21,367
  • 6
  • 52
  • 86
  • I maybe missing something, that may be because I used to the C, C++ and C# family. But what the point of Scala if I can't use it to make something which will run outside of Eclipse unless I download more plugins and change the build definitions manually? – Roee Gavirel Jul 23 '13 at 07:41
  • I'm sure that you can, I just don't know how to assemble a project within Eclipse, cause i'm working with IDEA with sbt-plugin. And the way how you r building/assembling your project has nothing to do with the language itself – 4lex1v Jul 23 '13 at 07:51