Superhero
Superhero

Reputation: 197

Is it possible to use Java to create dll?

Want to create animation dll for Window XP Is it ok to create Java2d animation and export as dll??

Upvotes: 14

Views: 25342

Answers (9)

Wolfgang Grinfeld
Wolfgang Grinfeld

Reputation: 1008

Yes, it is possible to generate DLLs from Java source code.

2 Methods I have used:

  1. IKVM
  2. Graal

IKVM is mature, but rather slow in runtime execution of the generated DLL.

Graal is fast, but early days and immature in the Windows environment. See https://openjdk.java.net/jeps/295 for further info.

There are other commercial options available as well.

Upvotes: 1

Andrew Rademacher
Andrew Rademacher

Reputation: 345

Actually, what Quentin said should work.
When you compile java to native with GCJ you first compile the .java files into platform specific .o (object) files. Presumably you would compile the .o files into a dll rather than an exe. GCJ also includes components like the garbage collector, and base java libraries. None of which require a JVM to run. The downer is that the dll would be huge. A simple "Hello World" app when compiled with GCJ is ~35MB, thanks to all the default libs and the garbage collector. Likewise your dll would be huge.

Upvotes: 2

Quentin
Quentin

Reputation: 943089

Well…

  1. GCJ is available for Windows.
  2. GCJ is part of GCC.
  3. GCC can create dlls.

It might be possible to put that together to build DLLs using GCJ.

Upvotes: 1

Patrick Cornelissen
Patrick Cornelissen

Reputation: 7958

No, IIRC you can't. DLLs are linked directly when loaded. Java code needs a jvm, so you can only provide a dll that starts a jvm and starts code there, but not all necessarily stuff fits in the dll.

You should not do this. It looks like you're trying to use the wrong approach for your problem.

Upvotes: 1

AaronLS
AaronLS

Reputation: 38367

There are "bridges" that allow Java and non-Java code to call into one another. Depending on what you are trying to accomplish, these might be useful as you could write your Java code and then call into it from a C++ or C# DLL, depending on which language you are creating your DLL with, which will also determine what kind of bridge you need. I have never seen a freely provided bridge though. All the ones I've found when looking had to be purchased.

Upvotes: 1

Carl Smotricz
Carl Smotricz

Reputation: 67750

I agree with bmargulies. It's probably feasible for an expert, but it would be a large DLL and you'd be mixing technologies that were never made to work together. It doesn't make sense to try this, in my opinion.

Upvotes: 0

o.k.w
o.k.w

Reputation: 25790

I doubt so, unless there's some 3rd party tools out there. For your case where graphics is involved, chances are even lower.

Upvotes: 2

bmargulies
bmargulies

Reputation: 99993

Yes. You need to write code in C++ to start the JVM with the invocation interface to JNI, and call into it. However, you may find it difficult to create windows in this way that integrate seamlessly with your Windows environment application to display your animation. This is a rather advanced JNI usage, and I'd recommend reading the JNI book before even trying a little bit of it.

Upvotes: 12

James
James

Reputation: 82096

I am pretty sure you can only create .Jar files from java not dlls

Upvotes: 2

Related Questions