1

I am using scala version 2.11.4, I have tried various options like sbt-assembly, build artifact (Intellij Idea feature), sbt package. Unfortunately, none of them worked form me.

I attempted following things :

  1. With sbt-assembly :

Created assembly.sbt file and added following line :

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")

build.sbt :

scalaVersion in ThisBuild := "2.11.4"

resolvers += Resolver.url("bintray-sbt-plugins",     url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }

I got the following error

[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]      com.eed3si9n:sbt-assembly:0.12.0 (sbtVersion=0.13, scalaVersion=2.11)
  1. With 'build artifact' feature using Intellij Idea 15

Able to create a jar. However, not able to execute it. Was getting following error:

Invalid or corrupt jarfile

For this I tried the command : java -jar JAR_FILE

  1. With sbt package :

Able to create JAR. However, not able to execute it. Was getting following error :

java.lang.NoClassDefFoundError scala/Function0

I was trying with the command :

java -cp scala-library.jar -jar JAR_FILE

Resolved

I am able to create jar by switching to scala version 2.10.5 and then used sbt-assembly plugin. Slightly disappointed with the fact that there is no available solution to create executable jar with latest version of scala.

aks
  • 1,019
  • 1
  • 9
  • 17
  • 1
    sbt-assembly is just the right tool for that and if I remember correctly in bundles scala in its default configuration, so what exactly have you done and what happens? – dth Feb 10 '16 at 12:51
  • sbt-assembly seems not to be working with scala version 2.11.4. I got error : [warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes. [warn] com.eed3si9n:sbt-assembly:0.12.0 (sbtVersion=0.13, scalaVersion=2.11) [warn] I have put following lin in assembly.sbt addSbtPlugin("com.eed3si9n" %% "sbt-assembly" % "0.12.0") and following line in build.sbt resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns) – aks Feb 10 '16 at 13:49
  • How is your assembly structured? Does it have a main class? Can you show it here? Is this for a client / desktop, or a server? – Suma Feb 10 '16 at 14:08
  • You do not need lines "resolvers += ... " and "ivyScala := ... " for sbt-assembly, definitely not with recent versions, and with sbt 0.13.6 or newer. If you copied them from some older examples, just delete them. – Suma Feb 10 '16 at 14:32
  • Which version of sbt do you have? According to the sbt assembly website sbt 0.13.6 and newer should use a different version of sbt. Make sure, you are running the current version of sbt and configure assembly according to their website: https://github.com/sbt/sbt-assembly – dth Feb 10 '16 at 14:38
  • @Suma : Its a client application. Yes it has main class under src/main/scala/app/Hello I have also added in sbt : mainClass in (Compile,run) := Some("app.Hello") – aks Feb 10 '16 at 17:46
  • @dth : I tried with latest version too. sbt-assembly version : 0.14.1 and faced same issues with it. – aks Feb 10 '16 at 17:47

2 Answers2

1

If you are using sbt-assembly plugin, the correct task to perform is called assembly. When using IntelliJ IDEA, sbt assembly needs to be performed from a command line, the IDE is still unable to perform such SBT tasks.

The resulting jar, which includes all dependencies, is usually called a fat jar - if you need some more searching, this is what to search for.

Community
  • 1
  • 1
Suma
  • 33,181
  • 16
  • 123
  • 191
  • I tried assembly task from intellijIdea by doing Run -> Edit Configuration -> SBT Task. But had no luck. Will try with command line. – aks Feb 10 '16 at 14:08
0

Since I can't comment yet, I'll use answer, but more of a question - I have been using sbt package extensively for exactly this. I cd into the directory that holds src/main/scala|java and running sbt package, and then pushing jar/war file to the desired destination, in my case jetty.

Can you explain exactly what you're doing, the output and details on the issue?

ekydfejj
  • 339
  • 2
  • 14