This repository has been archived by the owner on Jan 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
INSTALL.J2SE
81 lines (52 loc) · 2.66 KB
/
INSTALL.J2SE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Overview
--------
The PHP JSR 223 interface associates a managed and persistent PHP
executable with a JSR 223 ScriptEngine.
This document describes how to call PHP methods from Java using the
JSR 223 interface. For example it is possible to use PHP as a script
plugin for a Java report engine such as BIRT; for formula fields,
group selection formulas, etc. Please see the INSTALL.J2EE document
for details how to embed PHP into a pure J2EE application server or
how to call Java methods from PHP.
The PHP/Java Bridge can be installed with one copy operation:
* the "JavaBridge.jar" and the "php-script.jar" should be copied into
the J2SE java.ext.dirs directory.
Install PHP into J2SE
---------------------
* Install Java 1.6 or above. For older Java versions you'll need the
script-api.jar contained in the JavaBridge.war file.
* Install PHP 5.1.4 or above into the operating system PATH. Or use
the Java system property -Dphp.java.bridge.php_exec=... to direct
Java to a specific PHP executable.
* Type: java -classpath JavaBridge.war TestInstallation
* Copy the created "JavaBridge.jar" and "php-script.jar" from the
"ext" folder to the J2SE library path. On Windows the location
depends on the version and vendor of the JDK (see java.ext.dirs from
the above RESULT.html). On Linux the directory is:
/usr/java/packages/lib/ext/
* Use the command "jrunscript" to evaluate PHP scripts from Java, for
example:
jrunscript -l php phpFile.php
or:
jrunscript -J-Dphp.java.bridge.php_exec=/usr/bin/php-cgi -l php phpFile.php
* A convenience ScriptEngine is available which makes it easier to
invoke PHP methods from Java. Example:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine e = manager.getEngineByName("php-invocable");
e.eval("<?php class f {function a($p) {return ((int)(string)$p)+1;}}\n" +
"java_context()->setAttribute('f',
java_closure(new f()), 100); ?>");
Invocable i = (Invocable)e;
Object f = e.getContext().getAttribute("f", 100);
System.out.println(i.invokeMethod(f, "a", new Object[] {new Integer(1)}));
((Closeable)e).close(); // release the continuation, flush output
* Another convenience ScriptEngine can be used to implement a
REPL. Example:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine e = manager.getEngineByName("php-interactive");
System.out.println(e.eval("$a=122"));
System.out.println(e.eval("$a=$a+1;"));
System.out.println(e.eval("echo $a;"));
* Please see the JSR 223 specification for details.
* Please report bugs/problems to the mailing list: