views:

218

answers:

2

I am new to the java/scala stack in general. So far I have a relatively simple scala application (not a webapp) setup and built build with maven2, and I'd like to be able to deploy the output to one or more production server (ubuntu on EC2, but that shouldn't matter I assume)?

My main questions are: 1) What's the best way to get all the dependent (third-party) jars installed on the production server? maven takes care of installing them on my development box, how does that work in prod? 2) I can run my app with mvn scala:run, but what's the right way to start the app in production? 3) How do I deal with subsequent deployments?

Any pointers/resources will be appreiated! Thanks a bunch in advance for helping a noob! :)

+2  A: 

I tend to use the Maven App Assembler plugin to package dependencies, my own code, and create startup scripts. Basic use is described in the excellent Maven book from Sonatype.

For the most flexibility, it can generate Java Service Wrapper scripts, which allow the application to be run either as a command line application, a Windows Service, or a Unix Daemon.

This approach is not specific to Scala applications. You just need to know the main class of your application, e.g. sample.Main$ in the code below.

package sample

object Main {
  def main(args: Array[String]) = println("hello world")
}
retronym
+1  A: 

retronym's answer looks like the best solution but if you just want something really simple you can use the Maven assembly plugin. All you do is add it as a plugin to you pom.xml then do mvn assembly:assembly and it will build you a jar with all your dependencies (including scala lib) unjared into it. So you can then just run your application with java -cp my.jar MyMainClass.

Dave