<?php
require_once "http://localhost:8080/JavaBridgeTemplate721/java/Java.inc";
try {
/* invoke java.lang.System.getProperties() */
$props = java("java.lang.System")->getProperties();
/* convert the result object into a PHP array */
$array = java_values($props);
foreach ($array as $k => $v) {
echo "$k=>$v";
echo "<br>\n";
}
echo "<br>\n";
/* create a PHP class which implements the Java toString() method */
class MyClass
{
public function toString()
{return "hello PHP from Java!";}
}
/* create a Java object from the PHP object */
$javaObject = java_closure(new MyClass());
echo "PHP says that Java says: ";
echo $javaObject;
echo "<br>\n";
echo "<br>\n";
echo java("php.java.bridge.Util")->VERSION;
echo "<br>\n";
} catch (JavaException $ex) {
echo "An exception occured: ";
echo $ex;
echo "<br>\n";
}
输出结果如下:
java.runtime.name=>Java(TM) SE Runtime Environment<br>
sun.boot.library.path=>C:\software\Java\jre1.8.0_171\bin<br>
java.vm.version=>25.171-b11<br>
shared.loader=><br>
java.vm.vendor=>Oracle Corporation<br>
java.vendor.url=>http://java.oracle.com/<br>
path.separator=>;<br>
tomcat.util.buf.StringCache.byte.enabled=>true<br>
java.util.logging.config.file=>C:\software\tomcat\conf\logging.properties<br>
java.vm.name=>Java HotSpot(TM) 64-Bit Server VM<br>
file.encoding.pkg=>sun.io<br>
user.country=>CN<br>
user.script=><br>
sun.os.patch.level=><br>
tomcat.util.scan.StandardJarScanFilter.jarsToScan=>log4j-taglib*.jar,log4j-web*.jar,log4javascript*.jar,slf4j-taglib*.jar<br>
java.vm.specification.name=>Java Virtual Machine Specification<br>
user.dir=>C:\software\tomcat<br>
com.sun.xml.bind.v2.runtime.JAXBContextImpl.fastBoot=>true<br>
java.runtime.version=>1.8.0_171-b11<br>
java.awt.graphicsenv=>sun.awt.Win32GraphicsEnvironment<br>
java.endorsed.dirs=>C:\software\Java\jre1.8.0_171\lib\endorsed<br>
os.arch=>amd64<br>
java.io.tmpdir=>C:\software\tomcat\temp<br>
line.separator=>
<br>
java.vm.specification.vendor=>Oracle Corporation<br>
java.naming.factory.url.pkgs=>org.apache.naming<br>
user.variant=><br>
java.util.logging.manager=>org.apache.juli.ClassLoaderLogManager<br>
os.name=>Windows Server 2016<br>
sun.jnu.encoding=>GBK<br>
java.library.path=>C:\software\tomcat\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\software\Java\jre1.8.0_171\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\software\Git\cmd;C:\software\Java\jdk1.8.0_171\bin;C:\software\Java\jre1.8.0_171\bin;C:\software\phpstudy_pro\Extensions\php\php7.3.4nts;C:\software\phpstudy_pro\Extensions\composer1.8.5;C:\software\wkhtmltopdf\bin;C:\software\nodejs\;C:\Windows\ServiceProfiles\LocalService\AppData\Local\Microsoft\WindowsApps;.<br>
java.specification.name=>Java Platform API Specification<br>
java.class.version=>52.0<br>
sun.management.compiler=>HotSpot 64-Bit Tiered Compilers<br>
os.version=>10.0<br>
java.util.concurrent.ForkJoinPool.common.threadFactory=>org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory<br>
user.home=>C:\Windows\ServiceProfiles\LocalService<br>
catalina.useNaming=>true<br>
user.timezone=>Asia/Shanghai<br>
java.awt.printerjob=>sun.awt.windows.WPrinterJob<br>
file.encoding=>GBK<br>
java.specification.version=>1.8<br>
tomcat.util.scan.StandardJarScanFilter.jarsToSkip=>annotations-api.jar,ant-junit*.jar,ant-launcher.jar,ant.jar,asm-*.jar,aspectj*.jar,bootstrap.jar,catalina-ant.jar,catalina-ha.jar,catalina-jmx-remote.jar,catalina-storeconfig.jar,catalina-tribes.jar,catalina-ws.jar,catalina.jar,cglib-*.jar,cobertura-*.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-daemon.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,dom4j-*.jar,easymock-*.jar,ecj-*.jar,el-api.jar,geronimo-spec-jaxrpc*.jar,h2*.jar,hamcrest-*.jar,hibernate*.jar,httpclient*.jar,icu4j-*.jar,jasper-el.jar,jasper.jar,jaspic-api.jar,jaxb-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,jmx-tools.jar,jmx.jar,jsp-api.jar,jstl.jar,jta*.jar,junit-*.jar,junit.jar,log4j*.jar,mail*.jar,objenesis-*.jar,oraclepki.jar,oro-*.jar,servlet-api-*.jar,servlet-api.jar,slf4j*.jar,taglibs-standard-spec-*.jar,tagsoup-*.jar,tomcat-api.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-i18n-*.jar,tomcat-jdbc.jar,tomcat-jni.jar,tomcat-juli-adapters.jar,tomcat-juli.jar,tomcat-util-scan.jar,tomcat-util.jar,tomcat-websocket.jar,tools.jar,websocket-api.jar,wsdl4j*.jar,xercesImpl.jar,xml-apis.jar,xmlParserAPIs-*.jar,xmlParserAPIs.jar,xom-*.jar<br>
catalina.home=>C:\software\tomcat<br>
java.class.path=>C:\software\tomcat\bin\bootstrap.jar;C:\software\tomcat\bin\tomcat-juli.jar<br>
user.name=>LOCAL SERVICE<br>
java.naming.factory.initial=>org.apache.naming.java.javaURLContextFactory<br>
package.definition=>sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.<br>
java.vm.specification.version=>1.8<br>
java.home=>C:\software\Java\jre1.8.0_171<br>
sun.arch.data.model=>64<br>
user.language=>zh<br>
java.specification.vendor=>Oracle Corporation<br>
awt.toolkit=>sun.awt.windows.WToolkit<br>
java.vm.info=>mixed mode<br>
java.version=>1.8.0_171<br>
java.ext.dirs=>C:\software\Java\jre1.8.0_171\lib\ext;C:\Windows\Sun\Java\lib\ext<br>
sun.boot.class.path=>C:\software\Java\jre1.8.0_171\lib\resources.jar;C:\software\Java\jre1.8.0_171\lib\rt.jar;C:\software\Java\jre1.8.0_171\lib\sunrsasign.jar;C:\software\Java\jre1.8.0_171\lib\jsse.jar;C:\software\Java\jre1.8.0_171\lib\jce.jar;C:\software\Java\jre1.8.0_171\lib\charsets.jar;C:\software\Java\jre1.8.0_171\lib\jfr.jar;C:\software\Java\jre1.8.0_171\classes<br>
server.loader=><br>
java.vendor=>Oracle Corporation<br>
catalina.base=>C:\software\tomcat<br>
file.separator=>\<br>
java.vendor.url.bug=>http://bugreport.sun.com/bugreport/<br>
common.loader=>"${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"<br>
sun.io.unicode.encoding=>UnicodeLittle<br>
sun.cpu.endian=>little<br>
package.access=>sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.<br>
sun.desktop=>windows<br>
sun.cpu.isalist=>amd64<br>
<br>
PHP says that Java says: hello PHP from Java!<br>
<br>
7.2.1 <br>
可以根据此文件输出来判断 Java 环境和 jar 包位置是否正确