Reputation: 337
I am having some trouble with creating a runnable jar file in Eclipse with Scala.
In Eclipse I have a Scala project that I wish to make into a runnable jar file. When I run the jar file it cannot locate the Scala standard library.
IDE - I am using Scala IDE for extending Eclipse for Scala usage.
Setup - To export right click on my project and navigate down Export>Runnable Jar File. I select my run configuration and set the path to my desktop. I have the 'Extract' library handling option selected. My run configuration is a Java Application with my main class selected. My main class is written in Java whilst the rest of the project is written in Scala. I then run the create jar file through Windows CMD with java -jar myjarfile.jar
.
Error - When I run the jar file a NoClassDefFoundError
is thrown when the program first encounters a Scala standard library class (scala.util.Random
in my case). The program runs my Scala files fine and even runs another project's files that I added as a project dependency under Eclipse. When I run the jar file with scala myjarfile.jar
it cannot find the main class. Even if using scala
did work it would not be acceptable because the user will likely not have anything related Scala installed.
I have researched similar questions on Stack Overflow and none of them have worked. So how do I access Scala standard libraries in my jar file? Packaging the Scala standard libraries into my jar sounds like a good option but I have not idea how to do this.
Upvotes: 1
Views: 1036
Reputation: 337
Create a pure Java project and delegate the main method to your core Scala project. Add the Scala standard library to the Java project (found here) and export it. It should work perfectly.
Upvotes: 0
Reputation: 14227
There are 2 options for package a runnable jar for Scala with SBT:
zip
, tgz
, RPM
, DEP
, Docker
.Upvotes: 1