13

I need to use the logic contained in some java classes. I found JNI, but that project seems not updated recently.

Is there a way to use it in a Delphi native application? I use Delphi 2009.

2
  • Approximately how much source code? is translation from Java to Pascal feasible? If so, it might be better. Commented Jun 8, 2010 at 17:14
  • It is for medical imaging java classes, I would really not risk to insert bugs. For sure having Delphi classes would be the best solution, but unfortunately there are not. There are DICOM delphi classes, but what I need is a specialization of them (DICOM-RT), and those do not exist for Delphi (at least I didn't find an implementation). Commented Jun 10, 2010 at 7:54

5 Answers 5

7

A newer solution than JNI is JNA, which also supports callbacks from (Delphi) DLLs. I found it easy to use.

Sign up to request clarification or add additional context in comments.

3 Comments

But does JNA supports also calling java classes or only allowing java to "consume native things"?
See jna.dev.java.net/#callbacks for an example where the native DLL calls a method in the Java class to enumerate all native windows. This could be extended to register methods which can be used by the Delphi DLL to communicate with the existing Java classes.
@mjn JNA is primarily intended for Java to call some native code and requires a Java process to be started in the first place, with some performance pernalties. According to the OP question JNA might not be the best choice.
4

You could try j-interop. The technique I should adopt is to build a COM wrapper of java business logic, and using this COM server from delphi throught interoperability.

Delphi can build a type library of a COM server, and you could istantiate the com server using this typelibrary. Type library is simply a wrapper of the server, exposing its interface to be used by delphi code.

The key to communicating with different platform softwares is called "interoperability".

You can find this also in .net versus win32. Tipically delphi code is win32 (exe or dll), and you can build communication protocol between delphi objects and .net assemblies or java bytecode using interoperability solutions.

Comments

2

With Java 6, it takes only a few lines of code to write a standalone web service server which then can be invoked from Delphi.

small step-by-step tutorial, using the free NetBeans IDE and Delphi:

more xamples:

Comments

0

Embed the VM in the native code. This worked for me. An example with c can be found here. http://java.sun.com/docs/books/jni/html/invoke.html

Comments

-2

I very much doubt it. Delphi Code gets compiled into an executable while Java code is executed by a Virtual Machine. So unless you launch a complete Virtual Machine inside Delphi code I see no way to easily include the logics.

1 Comment

You need tro launch the virtual machine only once, and do multiple calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.