Hydra Java Plugin Interface in Delphi

I´m currently evaluating possibilities of mixing delphi and java together.
The idea is as followed :
Delphi Client shows and display GUI (in legacy software) and can interact with a nonvisual java plugin. The Javaplugin is resposible to communicate to a REST-Server.

I´ve written a simple Host in Delphi which loads a nonvisual plugin from java.

[Code - Delphi]
FModuleManager := THYModuleManager.Create(nil);
FModuleManager.AutoLoad := False;
FModuleManager.ResolveInterfacesToOwner := True;
FModuleManager.EnforceSecurity := False;
FModuleManager.LoadJavaModule(‘D:\RestClient.jar’);

FModuleManager.CreateNonVisualPlugin(APluginName, hPlugin);

The plugin is not nil and Start\Stop etc seems to work flawless.

Now i want to extend my Java Plugin by adding a crossplattform interface to it as described in https://docs.hydra4.com/Plugins/NonVisualPluginsJava/.

[Code - Java]
public interface ITestInterface extends HYCrossPlatformInterface
{
String GetText();
}

and implement it onto my PluginImplementation.

[Delphi - Code]
ITestInterface = interface(IHYCrossPlatformInterface)
[’{9CC48BD1-1B37-454E-9A19-0963468A4315}’]
function GetText(): string;
end;

When i try to QueryInterface it returns nil. My guess is either I´m missing something or java plugins has to be designed differently. I just dont find the missing clue within the documentation.

Hi,

this won’t work in this way.
you have miss

To access plugin’s custom interface methods this plugin should be first imported into the host application. This can be done via a button in the solution explorer’s header.

so you need to import java plugin with IDE wizard ( IDE->Tools->Hydra->Import Interfaces from Java module).
After this correspondent code for executing of java method will be created.


2019-12-05_16h56_51

I tried to import the File but getting Errors. I checked my jvm version and it seems to be running.

Client and jar file is build in 64 Bit. I will be out of town until monday and then recheck if there is anything i can do.

can you check, how your plugin is imported in Visual studio, pls?
correctly or also gives some errors?


Do you have JAVA_HOME system variable that references to openjdk folder?


Try to install 32bit jdk too - Delphi IDE is 32 bit and it can’t use 64 bit dll from 32bit process.
after import from java module was generated, you can switch to 64bit jdk again

Good morning!

can you check, how your plugin is imported in Visual studio, pls?
correctly or also gives some errors?

Since we don´t use Visual Studio at work ive installed a Trial to verify it.
I reinstalled Hydra in order to install the Visual Studio integration.
The Results are as followed:

Do you have JAVA_HOME system variable that references to openjdk folder?

Yes it seems to be correct. I´ve using Eclipse JEE Build 09 2019…
I don´t have any issues with Java at all, just with the plugin import from hydra.
2019-12-09_08h20_57

Try to install 32bit jdk too - Delphi IDE is 32 bit and it can’t use 64 bit dll from 32bit process.
after import from java module was generated, you can switch to 64bit jdk again

This is a very difficult solution. Java has not been delivered as 32-Bit version since 8.231 (thats the highest version i found).
They are only release 64-Bit solutions. If i would need to switch my Envirements each time i import a new interface this can be a time consuming task (atleast in the first
phases of development). Delivering plugins based on an old runtime also might cause security problems for our customers.

The most interesting part is also : I can run the java based hydra plugin. I can perform the start() task without any issues. I just cant import interfaces.

Edit:

For testing purpose i switched to Java 8.221 32-Bit and the import itself worked but once i want to compile it, it says : Exception RestClient_Import.pas(35): E2035 Not enough actual parameters.
Self.JVM.Reflection.CallObjectMethod(Self.InstanceID, lmethodId) requires a third param.

Hello

Sorry for the inconvenience this caused. The reason for this issue is that 32-bit process (RAD Studio or Visual Studio, that is still 32-bit) cannot load 64-bit JVM dll into process.

We will figure something out regarding this (most probably we will just start a command line tool as a separate 64-bit process under the hood).

There is no need to develop something against old JVM. It is (was) used only once to perform the import process and to generate the wrapper code. The plugin itself can work on the modern JVM version.

Sorry for the inconvenience again

Thanks, logged as bugs://83625

pls update method as

var
  lmethodId: JMethodID;
  args: JValueDynArray;
begin
  lmethodId := Self.JVM.Reflection.GetMethodId(Self.ClassID, 'GetText', '()Ljava/lang/String;');
  SetLength(args, 0);
  result := Self.JVM.ValueConverter.ConvertToString(Self.JVM.Reflection.CallObjectMethod(Self.InstanceID, lmethodId, args));
  exit;

Thanks, logged as bugs://83626

bugs://83626 got closed with status fixed.

the fix for methods with no parameter will be in next public release

I tested the change with params and it worked. Its still time consuming to switch java version each time but as antonk described there is a requirement for a solution.
From consumer view i would love a small tool where you just link your jar file as input, select .NET or Java as output and a directory where to drop the code and it generates Files for you without the requirement of an IDE-Integration.

From my perspective i can adance further for now. Thanks for your fast service!

Anton logged such issue (#83625) for creating a tool that will do as you described.

1 Like

I just thought i share some wisdom i obtained recently. This still not means there is no need for a 64-Bit Java wrapper but it can help for now as workaround to resolve Issues.

You can get 32\64 Bit OpenJDK through https://adoptopenjdk.net/.
I installed x86 version as Hotspot and x64 as OpenJ version (same not possible through their installshieldshield kit). I can run Eclipse Version: 2019-09 R (4.13.0) without any issues. as Systemenvirement i used C:\Program Files (x86)\AdoptOpenJDK\jdk-13.0.2.8-hotspot.
Now it seems Eclipse takes x64 to run java and allow me to build .jar files. Delphi on the other side takes x86 version and i can import java written plugins. So far it looks doable as workaround but there is no 100% safety it will work in all aspects. Still testing… still researching.