|
From: <php...@li...> - 2008-03-10 12:42:34
|
Hi,
> With Runner.getRequiredInstance(). This allocates a Java continuation
which has full access to your Java objects.
> Please see the INSTALL.STANDALONE document for details.
Ok, so here is what i have done, following the instructions given by
INSTALL.STANDALONE and INSTALL.J2EE
I have my very simple java application:
package app;
public class Main {
public static final String JAVABRIDGE_PORT="8091";
static final php.java.bridge.JavaBridgeRunner runner =
php.java.bridge.JavaBridgeRunner.getRequiredInstance(JAVABRIDGE_PORT);
private static int obj;
public static void main(String[] args) {
obj = new Integer(15);
System.out.println(getObj());
while(true);
}
public static int getObj() { return obj; }
}
I make a jar archive from it (phpjava.jar). The jar contains:
app/Main.class
META-INF/MANIFEST.MF
The Manifest is:
Manifest-Version: 1.0
Main-Class: app.Main
Created-By: 1.5.0
Class-Path: JavaBridge.jar
I put the archive into my deployment directory 'ext'. This directory
contains:
- java/Java.inc
- hello.php
- JavaBridge.jar
- phpjava.jar
According to the manifest of JavaBridge.jar, I have also put in 'ext' (just
in case):
- php-script.jar
- script-api.jar
Here is the php script:
<?php
require_once("java/Java.inc");
java_require("phpjava.jar");
$myClass = new java("app.Main");
$obj = $myClass->getObj();
echo $obj;
?>
I launch the JavaBridge.jar by right-clicking on it and 'execute with
java...' and select the socket.
I execute in a shell: java -jar phpjava.jar
The value of 15 appears and then the application continues running because
of the while(true) loop.
I try to connect through http://localhost:8091/hello.php
The value of 0 appears.
The VMbridge.log warns me that the port is already being used.
Meaning that with php, it launches another instance of my Main.class
What am I missing ? For me, the "new java(app.Main);" line in the php script
is not the correct one if I want to get the already allocated objects.
Is 'runner' the variable I should use from php or is it a variable used by
the bridge ?
Which kind of methods can I call to access my allocated objects ?
> But why don't you simply call into the Java continuation and use the
objects already allocated by your Java application?
I would love to :)
Thanks for your help
Regards,
--
# !! brOl_oUilLe -->
|