Deployment strategy for Scala fat clients with SBT

What is the “way to go” if I want to build a self-contained, all including fast JAR with SBT?

Is there any common deployment strategy?

The usual tool for that is sbt-assembly.

1 Like

I tried this already but for me it appears not to work.

When I try to run the application with java.exe -jar config-editor.jar I get

Error: Main method is not static in class globalconfig.ConfigEditorApplication$, please define the main method as:
   public static void main(String[] args)

The main class looks like this:

package globalconfig

import javafx.application.Application
import javafx.stage.Stage

class ConfigEditorApplication extends Application {
  override def start(primaryStage: Stage): Unit = {
   /* ... implementation .... */
  }
}

object ConfigEditorApplication {
  def main(args: Array[String]): Unit = {
    Application.launch(classOf[ConfigEditorApplication], args: _*)
  }

and the build.sbt:

name := "ConfigEditor"

version := "0.1"

scalaVersion := "2.13.1"

mainClass in assembly := Some("globalconfig.ConfigEditorApplication")
assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x => MergeStrategy.first
}

Which JDK you used to build the project and which JRE are you using to run it?
BTW, can you share a MCVE so we can test it.

Have you tried renaming the object or the class so there is no ambiguity. Perhaps sbt isn’t smart enough to pick the correct class in this instance?

1 Like

I’m a fan of coursier for making all-in-one executable jars

2 Likes

When I tried to create the requested MCVE I re-organized my build.sbt and now it works.

But I am not sure what the reason was.

Thank you so much for your time and help!

1 Like

Yes, the unijar strategy is pretty limited. Look at coursier install.

2 Likes

I was more thinking of the bootstrap utility. It’s not got the best documentation, but it is pretty powerful once you know everything it can do.

Brian Maso

Can you poitn me a link to this utility?

He is referring to this: https://get-coursier.io/docs/cli-bootstrap

1 Like

Slightly off-topic, but maybe one of you can give me a qick answer (nothing came on Stackoverflow, tho):

Following this tutorial, I am asked to add enablePlugins(WindowsPlugin) to my SBT configuration.

I did this by stating exactly this line in my build.sbt but all I get is “Cannot resolve symbol”. Do I need to add the dependency somewhere?