Using a java class from Delphi - java

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.

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

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.

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:
Delphi and Java Integration using Web Services
more xamples:
http://www.theserverside.de/webservice-in-java/
http://www.torsten-horn.de/techdocs/jee-jax-ws.htm#Minimaler-Webservice

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

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.

Related

How to pass dictionary in c# as parameter to the soap web service method implemented in java [duplicate]

I have a Java API in jar file with some dependencies from other jar files.
Is there any way to call a specific method from this API, like using PInvoke from .NET?
Here you go :) I've used it myself and was very please with the implementation.
IKVM: Using Java API's in .NET Applications
(1) If you just want some libraries
from Java.
(2.1) If you have access to
the code.
(2.2) Last resort,
dynamically load the Java into .Net
(interpreter)
I don't think it will be an easy task to interoperate .net and java. May be you could use sockets, and use them to send messages from one environment to another. It is just an idea, though.
EDIT:
I have found some libs that say they can do this:
http://www.jnbridge.com/
http://www.codeproject.com/KB/dotnet/Espresso.aspx
You can use CORBA to "call" java methods from .NET.
For .NET here you can find some CORBA libraries.
Java SDK includes CORBA capabilities so you don't have to download 3rd party libraries.

JACOB - Remote Dispatch call to COM Interface

I'm using JACOB in order to write message to a COM interface.
Dispatch dispatch = new Dispatch("<Interface Name>");
Variant response = Dispatch.call(dispatch, <DISPID>, message);
This works perfectly on localhost. But how can I use JACOB api to call interface on some other Machine/IP Address
JACOB seems to be unable to remotely access (DCOM call).
JACOB Project mailing-list FAQ
Can I call COM component across machines or operating systems?
The answer to this question is No. The way jacob is implemented is using JNI and a c++ DLL designed for the windows platform. COM is a binary standard defined by Microsoft as it hasn’t been ported over (as far as I know) to any other platforms yet. Jacob is only a java bridge for COM which defines how components talk to each other when they are on the same machine. The DCOM standard defines how components communicate across networks, but Jacob has no support for DCOM.
Solutions:
Commercial products, like J-Integra support the DCOM protocol natively.
Use RMI. Make a wrapper for the Jacob classes, and RMI'ify it. It actually works, but the Jacob lead didn't want to make the classes implement serializable, making the whole operation slightly difficult.
Use Web Services. Expose the stuff you'd like to have as a Web Service, and use SOAP and snacks on the Java side to access it.
Alternatively, it may be useful if the locally working COM object supports remote access internally.
It seems like the following article.
Jacob connect to Remote Computer for WMI support
ADODB Recordset Example
The JACOB Project: A JAva-COM Bridge
Downloads
The JACOB binary distribution (jacobBin_XX.zip) includes:
jacob.jar: a JAR file for the java classes which you must add to your CLASSPATH. The package names replace com.ms with com.jacob (for example com.ms.com.Variant maps to com.jacob.com.Variant.
jacob.dll: a small Win32 DLL which you must add to your PATH.
samples: provided in Java source and compiled form to demonstrate various features of the product. In particular, a set of wrapper classes for Microsoft® ADO are provided as samples.
The source code is available in the JACOB source distribution (jacobSrc_XX.zip), which includes both the Java and C++ code. The source distribution is a superset of the binary one, so you don't need both.
Others seem to have other libraries, not JACOB.
A pure Java DCOM Bridge with j-interop
j-interop/j-interop/src/readme.htm
In Addition:
Similarly, it can not be called between computers connected via LAN.
Also, it is not possible to call local COM objects remotely with VC ++ or .NET language.
The workaround is to create a proxy application to call the local COM object on the remote computer.
Design the main application and the proxy application arbitrarily so that they can communicate with each other using a socket or other means.

Is it possible to invoke a .NET Core app in Java?

I have a .NET Core (console) app that I would like for a Java app to depend on. Essentially I would like to be able for the Java app to invoke a multi variable method in the .NET Core app and then pass the result back to the Java app. It would be nice if the .NET Core app could be embedded in the Java app. I have previously seen .NET Framework specific solutions to this problem, but since this would only be relevant on Windows, I would like a solution that also works on Linux.
In the past there were some technologies such as IKVM.NET and COM Interop wrappers but the former is defunct and the latter probably wouldn't work on Linux.
Since you own the .net core code, I would take a more modern microservice approach. I would design the .net core app to be a REST API running as a console app listening on a port. I'd have the Java application spin up the console app, invoke the methods passing JSON back and forth and then spit it down when complete.
From my actual knowledge this nuget package JCOBridge is able to do what you are asking for.
Until now it supports linux for x64 architecture.
I tried the templates available on Templates and them works on my Ubuntu 18.04. The same templates works on Windows.

Connecting to IOCP server in Java (Android)

I'd like to make an Online Game with Android.
I'm planning to make Server with IOCP model via C++. This should work fine, the problem is the client.
IOCP client example in C++ uses WSASyncselect or WSAEventSelect.
I couldn't find any Java examples that same work like async socket.
Questions:
Is there anything like WSASyncselect() in Java?
If not that, how could i do it?
The JDK 7 Windows implementation of the Java 7 "NIO.2" classes
AsynchronousSocketChannel
AsynchronousServerSocketChannel
AsynchronousFileChannel
call the WSA[...] functions of the Windows "Overlapped IO" API behind the scenes.
For more in-depth information check out the OpenJDK repository folders containing the implementation .java sources along with their corresponding .c native sources and JNI bindings
.

Calling dll in Servlet

I have a situation. A device connected to PC(client side) via COM. The vendor provide me a dll to exchange data with the device. I would like to create a java web-app to collect data from many devices(connected to backend through PCs). So how can I call dll from a servlet? Thanks in advanced!
The straight-forward solution is using JNI or JNA. You should learn appropriate tutorial from Oracle to learn how to do this.
But probably you can do it easier. If for example this DLL is ActiveX you can create script (VBScript or JScript) and then run it from java using utility named cscript. Other possibility if this DLL already knows to run as a stand alone application (or you have separate command line app that runs this DLL and provides you CLI.). In this case I'd recommend you to use it unless you have serious performance constraints. It is much easier to run command line application from java than coding JNI.

Categories

Resources