7

I'm trying to find a way to convert a dll to a jar file. I have a .net application that communicates with a java application. The core entities are .net objects which I have to duplicate manually in java. I've read about IKVM but it seems that it converts only jars to dlls and not the other way around.

Edit: If there is a tool that creates java classes from a dll it is also fine. Thanks in advance

Dennis Nerush
  • 5,473
  • 5
  • 25
  • 33
  • Jar and dll are generated by two different compilers isn't it. – mihirjoshi Jun 02 '13 at 19:44
  • That's right. I'm trying to find a tool that will read the dll and compile it to a jar. Or will create the matching java classes. – Dennis Nerush Jun 02 '13 at 20:08
  • 1
    I strongly doubt that such a tool exists or is even possible. – Hovercraft Full Of Eels Jun 02 '13 at 20:27
  • I think i can suggest you to look to project sqlite-jdbc. IT'S NOT WHAT YOU ARE LOOKING FOR. Howether, it implements the idea you want to realize: it takes dll library for sqlite (and linux/macos so's, but that's not the point), and makes a jni wrapper for it. All these shared libraries are packed into final jar, and so java driver can call native built-in library. I'm sure you can look to it's build process, and copy in on your project. It's source code can be found here: https://bitbucket.org/xerial/sqlite-jdbc – infthi Jun 03 '13 at 09:00

2 Answers2

5

There isn't such a tool.

A dll is a natively compiled library. That means its been compiled down to machine code. Probably compiled by a C/C++/C# compiler.

A jar file is a zip file that contains '.class' files, which are files compiled down to 'java virtual machine code'. Probably compiled by a java/clojure/scala compiler.

These are two very different incompatible things.

It's not impossible to create such a tool that would do this translation, but it would definitely be an extremely difficult task, as it would entail translating from one machine code, to another, and would need to manage multiple issues like dependency solving, different type structure etc.

HOWEVER, I'm imagining that you want to do this because you want to use a DLL within some java code. That is somewhat possible, but is actually quite complicated. You'll need to use the JNI.

Take a look at this question as it might help you achieve what you want to do: Calling C++ dll from Java

Community
  • 1
  • 1
chamakits
  • 1,865
  • 1
  • 17
  • 26
3

This is actually an easy task to perform. Converting .dll to .jar is as simple as using com4j and a couple of commands on the command line.

  1. Download com4j.
  2. Open command line and navigate to com4j directory in above step.
  3. Execute below command.

java -jar tlbimp.jar -o outputFolder -p nameOfPackage "pathToFile"

  1. Then jar the results with the following:

    jar cf desiredJarName.jar folderYouWantJard