imichaeldotorg
imichaeldotorg

Reputation: 469

Generate a JAR from one Scala source file

I have no Scala experience, but I need to create a JAR to include on a project's classpath from a single Scala source file.

I'm thinking there is a relatively straightforward way to do this, but I can't seem to figure it out.

The Scala file is here: http://pastebin.com/MYqjNkac

The JAR doesn't need to be executable, it just needs to be able to be referenced from another program.

Upvotes: 1

Views: 77

Answers (1)

Jiri Kremser
Jiri Kremser

Reputation: 12847

The most convenient way is to use some build tool like Sbt or Maven. For maven there is the maven-scala-plugin plugin, and for Sbt here is a tutorial.

If you don't want to use any build tool, you may want to compile the code with scalac and then create the jar file manually by using zip on the resulting class files and renaming it to jar. But you have to preserve the directory structure. In your pastebin you use the package org.apache.spark.examples.pythonconverters, so make sure the directories match.

Btw, if you want to just integrate this piece of code with your java project, and using maven, you can have the scala code in your 1 project as well (in src/main/scala). Just use the maven-scala-plugin plugin and hook it to the compile phase, or some sooner phase if your Java code depends on it. However, I don't recommend mixing multiple languages in one project, I would split it into two separate ones.

Upvotes: 3

Related Questions