Converting a Scala library to a DLL (.NET)

2019-07-21 01:38发布

问题:

I'm trying to create a Dll out of a scala-class. I'm using IntelliJ together with SBT. I've already found a way to convert .jar files into a Dll, using the ikvm-converter. Now the problem: When I use "package" under SBT to create a .jar file out of my .scala file and try to convert it afterwards with ikvmc into a Dll the resulting library is empty when integrated in C#...

For example converting the Jama-Library (which is written in Java) works fine, where converting Scama (written in Scala) does not work.

Is there a way to do this conversion of scala code into a dll? Is there a "Scala to Java"-conversion tool?

Best Regards, Christoph

回答1:

I have no knowledge of .NET, but judging from SK-logic's and your comments to the questions: sbt package does not include the Scala runtime library, because it assumes you are going to export your project as a library to be used within other Scala projects.

Therefore, you will need to create a "fat" jar that contains the runtime. For example, in this blog you can see how the author creates a fully self-contained executable, by converting both the project jar and the runtime jar.

There are different tools to do that with sbt. The easiest would be sbt-assembly, but you will end up with a very large file, because it just adds the whole runtime. If that is a problem, you may want to filter the runtime instead, using the proguard plugin. More on this topic in another StackOverflow entry.