2

Let's suppose I have a file called Main.scala that I want to compile and run.

In a normal environment I can just do scala Main which automatically performs compilation and runs the file.

Now I am trying to deploy scala source code to another Server, on which I am not allowed to install scala. It is just possible to copy files (such as scala-library.jar and scala-compiler.jar) and Java 1.6 is pre-installed.

It would of course be possible to compile to bytecode locally using scalac Main.scala and execute the resulting .class-files using java -cp [...] Main.

For my workflow it would, however, be better if I could just checkout and compile the scala sources on the remote server directly.

Is there any possiblity to realize this compilation task with the tools available or by copying additional binary/jar files?

2
  • Why do you think checking out the scala sources and compiling them on the server would be a better idea than compiling them locally into a JAR and then deploying it on the server? It's on the JVM, take advantage of it. Commented Mar 11, 2015 at 16:20
  • @Zoltán Because the Server(s) may be located in another country, only accessible via VPN. Now the total size of the source is several hundred MB and if I need to make small changes, I wouldn't have to copy the entire .jar over the slow connection again. Commented Mar 12, 2015 at 6:36

1 Answer 1

2

I would strongly suggest that you use a build tool. Many open source projects use sbt (http://www.scala-sbt.org/). You can use an sbt plugin (https://github.com/sbt/sbt-assembly) to create a fat jar with all your dependencies.

You can also use Maven and Gradle.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, yes, using a build tool is definitely the way to go for managing compilation tasks in the project. I have ant available on the remote server but might also be able to use sbt. Does the compilation of scala using sbt work by only using the corresponding .jar-files or would I still need the scala and scalac commands?
@MichaelLang - I don't think you will need scala and scalac anymore. All you need to run sbt is java. sbt can bootstrap itself from a jar file. I would suggest that you spend some time looking at a simple example built using sbt and then go from there.
@MichaelLang You don't need to use sbt on the remote server at all; you create a runnable .jar with sbt-assembly, then copy it to the server and just run it with java -jar ....
This approach seems to meet my requirements pretty well. Nevertheless I'd still be interested in a solution which does not require internet access. After retrieving the .jar-files, sbt will simply issue some commands executed locally as well, right? Couldn't figure them out though. I'm guessing the easiest solution here would be to set up a maven repository that is reachable over the existing VPN connection of my servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.