calling java code from PHP - java

I have a PHP web application developed using symfony framework. I want to call some Java code from within my PHP pages. Java code is distributed to multiple jar files and there is one interface available to access the functionality. The input and outputs of the Java interface are XML files, text files, Java beans and some more complex objects.
Is there any bridge available in PHP to call complex Java methods or some other solution to this problem. Alternatively, I have to write soap web services to solve this problem.

You may want to look at these:
Zend Platform Java Bridge
PHP/Java Bridge
HTH

you could run the java code by exec or shell_exec
ex.
shell_exec("java whatever.jar $parameter1 $parameter2");
Webservices would be the nicer solution though. IMO

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.

Can Electron apps be integrated with java code?

As node.js still lacks important functionality which exists in Java, I would like to use Java instead of node.js, and create the client using a web language (html, js, css..).
Electron is cross platform and so does java so it seems fit to have a solution getting the best of both worlds.
Does someone know of a way to integrate electron with java or have a different solution to the problem?
I made something similar, Java back-end with Electron GUI.
You can do it in more ways, it depends on what you need.
You can create a jar file and then execute it like terminal:
https://nodejs.org/api/child_process.html
Or you can open a socket communication and talk on a Port. (A lot of documentation:
Java (web)socket - Node.js client.io)
In this second way, you can do everything you want, but you have to create your communication protocol.
Your path is not foolish, I am very satisfied of the communication and usage in my work with Java + Electron .
I've created a small PoC where Java process is integrated with Electron front-end: https://github.com/jreznot/electron-java-app There you will find a simple TODO List application built with Vaadin/Jetty and Electron.
Personally i made my back-end java communicate with the front-end by creating a file with te data then sending it to the main.js to be processed.
DBus and winDbus seems to be an option here.
It creates nice abstraction and separation between "frontend" and backend
https://sourceforge.net/projects/windbus/
I'm going to test it on my own soon

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.

What's the recommended way of running Java from PHP 5.2?

I want to call Java from PHP 5.2, running either on a webserver or from a command line script.
From PHP 4, this seems to be simple, and just involves installing the PECL Java extension.
Example code from the PHP 4 extension:
<?php
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
// demonstrate property access
echo 'Java version=' . $system->getProperty('java.version') . '<br />';
?>
However, this extension doesn't exist on PHP 5.
What is the closest alternative for PHP 5?
edit:
Really I'm looking for an interface similar to either a C PHP extension or to that provided by the PHP 4 Java extension. The Java program is fairly small and only needs to retain a small amount of state between calls and doesn't need to run asynchronously. The PHP script would only be running a small number of instances simultaneously.
This would also need to be deployed to multiple machines (running Ubuntu 9.x and Debian Lenny), so it should be simple to install.
This project seems to be a good bet: http://php-java-bridge.sourceforge.net/pjb/
Since you want to keep state at the java site I'd either use a java process that listens on a plain socket or use a simple embedded webserver (winstone or jetty) if you are more fluent writing servlets. Some other possibilities are listed at this related question: What is the best approach for IPC between Java and C++?
Now quite what you asked for, but you could have a look at Caucho's Resin, and in particular their Quercus which is a 100% Java implementation of PHP, it allows integration of Java and PHP.
I have a project that uses a Java program to fetch some data. It's quite simple, but I found that
$java_command="cd /var/java_dir && java my_java_program $myparam1 $myparam2";
$result=exec($java_command,$output,$return_code);
works just fine.
Zend Server also has a built-in daemon allowing you to access Java functionality from within PHP. It works right out of the box.

Best solution for using EJBs from Excel

We would like to give access to some of our EJBs from Excel. The goal is to give an API usable from VBA.
Our EJBs are mostly Stateless Session Beans that do simple CRUD operations with POJOs.
Some possible solutions:
Exposing the EJBs as WebServices and create a VB/C# dll wrapping them,
Using Corba to access the EJBs from C#,
Creating a COM Library that uses Java to access the EJBs,
Pointers to frameworks for these solution or other ideas are welcome.
You could take a look at IIOP.NET, which addresses this issue.
If you have a fairly recent ejb container, the cheapest and easiest should be to expose your beans as web services and call it from VB/C#. This doesn't require any extra tool or library.
I work on an open source project called XLLoop - this framework allows you to expose POJO functions as Excel functions.
It consists of:
An Excel add-in (XLL), which communicates over TCP to:
A Java server/library, which invokes java methods.
You could embed this java function server in an EJB and have it deployed as part of your app server.
Back in the VB6/COM/DCOM times we used the suite J-Integra to accomblish this task. I have no experience with the .NET version though.
I highly recommend IKVM. It is a java byte code to .NET assembly compiler (i.e. JAR --> DLL) and I have used it to create live JMX links and listeners in an Excel automation server. It should not be difficult for you to create a .NET assembly of your EJB client stubs and supporting libraries.
//Nicholas
You could try Obba (I work on this project):
Obba is a Java object handler for spreadsheet applications.
It provides a bridge between spreadsheets and Java classes, such that spreadsheets can be used as graphical user interface for Java libraries. Accessing your Java library form the spreadsheet requires no glue code (no VBA needed, no special Java code needed). Objects are instantiated by their original constructor. Constructors and methods are invoked using a "by name" reflection. A spreadsheet-specific factory method is not necessary. Obba provides the functions to handle objects in spreadsheets.
The Java virtual machine providing the add-in may run on the same computer or a remote computer - without any change to the spreadsheet, i.e., object referenced in the spreadsheet can reside on remote Java virtual machine.

Categories

Resources