Exporting Scala project as jar from Eclipse

孤人 提交于 2019-12-06 10:21:16

Here is what worked for me: 1. Create scala project 2. Create Wrapper java project 3. Add the scala-library.jar to you java project build path.

So you only need the 3rd step in addition since the rest looks similar to what I did. Then you can happily use: java - jar file.jar

EDIT: How to create a JAR File which contains Scala/Code which can be consumed by another Java Project, using Scala - Eclipse IDE.

  1. Create a new Scala Project and define an object with a main method as entry point.
  2. Now create a new Java Project and add your Scala Project to the new ones buildpath. Additionally add the scala-library.jar to the Java project.
  3. Now create a Wrapper class in the java project which calls your entry point class from the scala lib. Run the wrapper class to create a eclipse run configuration and test if you can call the scala project.
  4. Use the Export->Java->Runnable JAR file, Wizard now on the wrapper project.The eclipse run configuration will be used as entrypoint into the JAR. Depending on your needs you may want to : extract required libraries into generated JAR or Package required libraries into generated JAR

Finally you get a complete packaged JAR which you can use like this:

java - jar wrapped.jar

For me, it was relatively straightforward.

  1. Develop and test the project using the scala IDE (or eclipse for java).
  2. once ready, generate the jar for the project using file -> export method.

for submitting the spark (i was writing something for spark), i just had to mention --class option for specifying the main class for the jar.

hope to help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!