使用Php-Java Bridge
我无法正确设置Php-Java Bridge
设置。
我会解释我做了什么。
- 我的网站是纯PHP的
- 对于我们的支付交易流程,我们需要设置一个php-java桥
- 我按照这个链接来设置桥接PHP-JAVA BRIDGE INSTALATION。
- 在这里,我了解到我需要一个私有的jvm来安装这个桥。
- 所以,我使用我的c-panel在Private JVM中安装了apache-tomcat-6.0.14。 安装后,它要求我将域映射到私有JVM。 所以我将我的域example.com(这是唯一可用的选项)映射到它。
- 然后它要求启用从Apache Web服务器到我的Java应用程序服务器的流量重定向(有一个复选框,我点击它)
- 最后它要求我部署WAR文件(JavaBridge.WAR是我的文件),并且everthing似乎很好
- 现在,当我访问http://example.com/JavaBridge/时,我可以看到javabridge示例,它运行正常。
到现在为止还挺好
现在我的问题从这里开始,当我尝试从php访问java类文件。 我创建了一个示例test.php
,并将以下代码放入其中。
getProperties(); //This Part echo's correctly and shows the data so it means i can access Java.inc Correctly $path_e24class = getcwd(). '/e24PaymentPipe.class'; //This part fails both test.php and java class file e24PaymentPipe.class are in the same directory in publich_html folder java_require($path_e24class); $pipe = new Java("e24PaymentPipe"); $pipe->setAction("1"); ?>
我的站点内容位于public_html文件夹中,WAR文件部署在私有jvm中。
这些是我收到的错误消息。
1) Warning: java_require() not supported anymore. Please use tomcat or jee hot deployment instead Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new e24PaymentPipe. Cause: java.lang.ClassNotFoundException: e24PaymentPipe VM: 1.6.0_22@http://java.sun.com/" at: #-10 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) #-9 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) #-8 java.lang.Class.forName0(Native Method) #-7 java.lang.Class.forName(Class.java:247) #-6 php.java.bridge.Util.classForName(Util.java:1518) #-5 php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-4 php.java.bridge.Request.handleRequest(Request.java:458) #-3 php.java.bridge.Request.handleRequests(Request.java:500) #-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1 php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0 http://example.com:portnumber/JavaBridge/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(3, 'java.util.Prope...', 'T', false) #1
最后我对java不太了解。 所以我被困在这里不知道该怎么做。
这是您可以遵循的一步一步的精彩教程 ,其中显示了所需的一切! 这有点旧(2007年),但不久前帮助了我。
还有另一种选择。 您可以安装Apache Tomcat并在那里部署您的战争。 只要您尊重端口设置,您可以在同一台计算机上同时运行httpd,同时运行多个tomcat实例。 你甚至可以用Apache httpd将它们放在前面。
你可以试试这个:
- 将您的代码打包到jar,并将其复制到java.ext.dirs,您可以在JavaBridge.log中找到它
- 将相关的类库复制到java.ext.dirs
- 重启JavaBridge的服务
祝好运!
get("hdfs://master:9000/user/hadoop/test-in/logo_cn.png", "/home/hadoop/1.png"); } catch (JavaException $ex) { echo "An exception occured: "; echo $ex; echo "
\n";} ?>
你可以在github上使用这个php实现,它与php 5.3一起使用。
有关更多信息,请参阅git自述文件。
你可以试试这个; 把JavaBridge.jar放在tomcat的lib文件夹中,例如apache-tomcat-7.0.12 / lib。
重启tomcat服务器然后,
$pipe = new java("com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe"); $pipe->setAction("1");
这样我创建了对象的php版本。
为什么不将e24PaymentPipe类放在Java应用程序的类路径中,并跳过以下两行:
// $path_e24class = getcwd(). '/e24PaymentPipe.class'; // java_require($path_e24class); $pipe = new java("fully.qualified.classpath.e24PaymentPipe");
您正在混合PHP端和Java端操作。 理论上,java_require(不推荐使用)被设计为在Java端工作。 您正在指定PHP端路径。
通过使用e24PaymentPipe库的纯PHP实现 ,您可以避免很多悲伤。
放弃
链接是我的库的github repo,但我没有写。 请参阅自述文件以获取原始学分。