How can I create a jar from some Scala source code?

醉酒当歌 提交于 2019-12-06 05:19:11

问题


How can I create a jar from some Scala source code? I want to use some of that code in a Clojure project of mine.

Is there a simpler way than doing batch files as in this SO question?

Thanks, Alex


回答1:


Scala is in no way special when it comes to what you do with the .class files produced by its compiler. Just use the jar command with the c action flag.

However, you will need to have the scala-library.jar file in the class-path when you run the program that uses the Scala-compiled .class files. And be careful to use the scala-library.jar for / from the same Scala Development Kit that you used to compile the Scala source. As of yet, there isn't inter-version binary compatibility for Scala-generated .class files.




回答2:


One way in which creating .jar can be "simpler" is to use simple-build-tool, which supports the package* targets and requires rather little time to set up and use.




回答3:


You could use the maven scala plugin or the buildr tool.




回答4:


This has actually really helped

If you are using eclipse then just export your project as a jar file

goto file -> Export ->java -> as a jar file

Just bit more explanation:

  1. Install the scala eclipse environment from typesafe
  2. Once you are done coding, export as a jar (file -> Export ->java -> as a jar file)
  3. from a command line you can run java -cp path_to_dependancies:your_newly_generated_jar:. your_main_object_name.

hth.



来源:https://stackoverflow.com/questions/3571237/how-can-i-create-a-jar-from-some-scala-source-code

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