I'm developing an application on Eclipse with Scala and a would like to create a .jar. I have found tuto to do that, but it use the package scala.tools.nsc and I don't know where I can found this thing.
I have tried too, to generate the .class and then with the command jar cmf ....
to generate the .jar
but when I launch the .jar
an error occur. (NoClassFound)
With sbt I have tried too, but when I compile my project that work with eclipse a lot of error appear.
Somebody can me explain how I can simply create a .jar with Eclipse or another tools.
Create a jar file using 'sbt assembly' command. If you run 'sbt assembly' command before adding plugin it shows errors. 2. Distribute all the JAR files necessary with a script that builds the classpath and executes the JAR file with the scala commands.
In the Create JAR from Modules window, select the folder icon in the Main Class text box. In the Select Main Class window, select the class that appears by default and then select OK. In the Create JAR from Modules window, ensure the extract to the target JAR option is selected, and then select OK.
To run scala programs with the java command, you need to include the scala library as a runtime dependency of your application. I'm including the same Compile. jar from the java example as a compile time dependency, to show how everything behaves. The scala runtime is just a jar file (scala-library.
Steps to get sources of a jar file as a zip :Drag and drop the jar for which you want the sources on the JAD. 3 JAD UI will open with all the package structure in a tree format. Click on File menu and select save jar sources. It will save the sources as a zip with the same name as the jar.
Eclipse has a build-in option to generate runnable jars, but it is well hidden. Also it does not recognize Scala's main() signatures, so you will have to create a Java class with a main() method.
Create a Java class with a main() method which simply forwards the call to your Scala code.
Then right click on your newly created Java class and select: Run As -> Java Application. This will create a runnable configuration which will later be used as a part of your runnable jar.
Now you are ready to dig out the runnable jar option from the Eclipse's menu: File -> Export -> Java -> Runnable JAR file
In the presented dialog select the Launch Configuration you have created earlier (in step2), name your jar (myapp.jar), select your dependency export options and click finish.
The jar will be created in the Eclipse's workspace by default.
Run the jar using the line: scala myapp.jar
Your question about missing images: Eclipse requires a manual refresh when files are added or removed. Right click on your project and select Refresh.
This concludes the tutorial on the highly intuitive Eclipse interface.
Note: Instructions for Eclipse version 3.6.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With