Converting a Scala library to a DLL (.NET) - java

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

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.

Related

IKVM.NET & Excel VBA

I'm using IKVM.NET in order to convert a Java library (signally, Strata) into a .NET library. Here are the steps I perform:
I download the latest Strata release.
I unzip all the JAR files contained into the lib folder of the archive to C:\Strata\, including the following auxiliary libraries:
commons-math3-3.6.1.jar
guava-26.0-jre.jar
joda-beans-2.4.0.jar
joda-convert-2.2.0.jar
slf4j-api-1.7.25.jar
I generate a keyfile for the library I want to create using the command sn -k "C:\Strata\Strata.snk".
Using the binary bytecode compiler of IKVM.NET, I convert the JAR files of Strata into a .NET library with the following command: ikvmc -out:"C:\Strata\Strata.dll" -keyfile:"C:\Strata\Strata.snk" -assembly:Strata -version:2.2.0 -fileversion:2.2.0 -target:library -platform:anycpu -recurse:"C:\Strata\*.jar".
Once the process described above is done, even if a few warnings concerning missing classes are shown, I obtain a working .NET wrapper of Strata. If I create a new Visual Studio project referencing the Strata.dll assembly, I'm capable of using its classes and methods without problems.
What I would really love to achieve is to make the wrapper work in Excel VBA macros, so that I can instantiate and use Strata classes in the subs, according to the contents of the sheets.
This is what I tried so far, but to no avail:
I register all the IKVM.NET libraries and the Strata wrapper into the GAC as follows: gacutil /i "C:\IKVM\IKVM.*.dll", gacutil /i "C:\Strata\Strata.dll".
I register the Strata wrapper as COM component and I create its types library as follows: regasm /codebase /tlb "C:\Strata\Strata.dll".
Now, when I open Excel and I go under Development > Visual Basic > Tools > References... I can see the TLB file of Strata (located at "C:\Strata\Strata.tlb") and I can add it to the current project. But as soon as I type something the window or I open the Objects Browser, Excel crashes without providing any meaningful information about what's going on.
I'm totally clueless about this issue.
Is my registration process correct? Do I have to register the IKVM.NET libraries too and create their type libraries? Should I include them into the Excel VBA project together with the Strata wrapper type libraries? Could the problem be caused by the fact that I'm using a x64 version of Excel and the wrapper has been compiled under AnyCPU? Do I need to edit the wrapper by adding a ComVisible attribute on every public class? May this problem be due to the fact that the wrapper contains weird method names like ā€œ\_Build01_\pā€?
Rather than use IKVM.NET you can use Java directly to build an Excel add-in.
To build an Excel add-in in Java instead of having to use .NET, see https://exceljava.com.
There is even a Strata-Excel project that you might be interested in that wraps the Strata library in an Excel add-in: https://github.com/exceljava/strata-excel
I think you should find this much more convenient than converting the Java libraries to .NET.

Java code reuse with pre compiled class including Main

I downloaded all the Apache POI downloadables recently, specifically poi-examples-3.11-20141221.jar wherein it includes pre-compiled examples like "How to Use".
The problem is I can't run the pre-compiled classes without Eclipse.
Specifics: poi-examples-3.11-20141221.jar
-> org.apache.poi.xssf.eventusermodel
-> XLSX2CSV.class
XLSX2CSV is already compiled with main() and I just want to simply run it without eclipse.
Links through other tutorials about JAVA Reference Class and Jar in Java will also be helpful.
Im new here so please be gentle.
Run it with the jar on the classpath, but not with the -jar option
For example, for the .xls to csv converter example XLS2CSVmra you'd do something like:
java -classpath poi-3.12-beta1.jar:poi-examples-3.12-beta1.jar org.apache.poi.hssf.eventusermodel.examples.XLS2CSVmra
Make sure that all the POI jars you need are on the classpath (.xlsx / XSSF needs more), along with any of their dependencies from the lib directory. See the POI Components Page for details of what jars you need for what

Difference between a jar file and a library in Java

NetBeans allows the programmer to add a library and a jar file.
What is the difference between a jar file and a library? Is library similar to GAC assembly as in Windows.
There are similar questions, but they are way too specific and I was not able to understand the difference.
to put things very simple : library is a collection of jars
You could like create a global library java-ee which contains all Java EE related jar files. Then you could use this global library in your different projects. It will be simpler to manage them; and adding in new projects.
A JAR serves the same function an an Assembly in the C#/.net world. It's a collection of java classes, a manifest, and optionally other resources, such as properties files.
A library is a more abstract concept, in java, a library is usually packaged as a JAR (Java ARchive), or a collection of JARs.
A jar file is zip archive containing among other files, the java class files. A Netbeans library contains resources required by the project, including jar files.
If well understood: A library is simply a folder that groups classes. For example in JDK, a library present there is a group of classes stored together.
If not mistaken a .jar file is a group of compiled classes in .class format and was created by Java creators so a program will be OS independent; which means within a JVM you will run your app in .jar format on a Linux, Windows, etc without re-coding tour app for various OSs.
This article explains it all..
It states
Java's libraries are commonly known as class libraries. However, Java
refers to class libraries as packages.

C++ library equivalent for Java?

What would be the equivalent of a library in C++ for Java? I have some classes I'd like to reuse as a library in multiple projects.
Thanks
Basically you build a jar file with the classes in, and then add a reference to that jar file on the classpath for both compilation and execution.
See the Oracle Jar File Tutorial for more information.

java cvs,svn file structure

I have recently learnt how to program in java, I was looking at some open source programs from sourceforge.net and after downloading these programs I don't understand the file structure most of the programs follow. Pretty much every program has src,bin,lib etc folders, how do I know the standard way of organizing my program. Is there any book or resource which explains this? also how do I compile this source code once I have downloaded it, to make a jar file from it
thanks
src is (usually) what it sounds like: source code
bin is (usually) shell scripts related to the product
lib is (usually) external dependencies needed for compilation
Most projects document how they build: look for a README or grok the project website. These days for a Java-centric project I would expect Ant or Maven.
What you have downloaded is actually a distribution version of the program. The directories as listed by carej are kind of a convention, mainly derived from how things are usually done on a Unix system.
Most projects supply some manual on how to build. This can be tricky if not all libraries (jars) used by the program are supplied in the distribution. Some of the Apache Commons project do it like this, thus forcing the user to download dependencies seperately.
If you just want to use the program try to find a binary version. This will usually consist of jars, scripts and documentation. Source distributions are useful if you want to look at the source and/or make modifications.

Categories

Resources