This code was created in order to allow the integration of Scala and a Windows DLL. It was entirely based in this example, so I just had to create the DLL and manage to integrate both platforms.
If your are used to JNI, you'll see that there is no much difference between Java and Scala, except that in the last you have to include Scala Library and Scala Reflect libraries in the source path (sure, there are few differences in coding).
In order to make it work in Linux or Unix, just follow those steps in the link above: it works like a charm.
In Sample1Scala folder, run the following commands:
scalac Sample1.scala
set SCALA_CP=%SCALA_LIB%\scala-library.jar;%SCALA_LIB%\scala-reflect.jar
javah -classpath %SCALA_CP%;.\ Sample1
- Sure, you must have Scala installed in your computer and SCALA_LIB variable configured to reflect its lib folder (search for those scala-library.jar and scala-reflect.jar files if you are not sure where they are);
- This will create the Sample.h file that is used in Sample1DLL project (created just as a reference in this last step). The Sample1.cpp file was created with the source code provided in the example referenced previously.
Then, compile the DLL and copy it to Sample1Scala folder; Lastly, run the following command to call Sample1 application.
java -cp %SCALA_CP%;. Sample1
Make sure you use the same target platform for your DLL that corresponds to the installed JVM (run java -version to check). If your JVM is a 64 bit version, compile to a x64 DLL, otherwise, compile it to a x86 DLL. These options can be configured in Visual Studio.