1

I am working on PHP-Java Bridge.

A syntax from my php file looks as follows:

require_once("java/Java.inc");
$address = new Java('com.odus.apg.cfa.java.address');

I have placed the package file cfa.jar which consist com/odus/apg/cfa/java/address.class file in TOMCAT.HOME/webapps/JavaBridge/WEB-INF/lib

And my php file is located at TOMCAT.HOME/webapps/JavaBridge

After this set-up I get

Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new com.odus.apg.cfa.java.address. Cause: java.lang.ClassNotFoundException: com.odus.apg.cfa.java.address VM: 1.7.0_40@http://java.oracle.com/" at: #-18 java.net.URLClassLoader$1.run(Unknown Source) #-17 java.net.URLClassLoader$1.run(Unknown Source) #-16 java.security.AccessController.doPrivileged(Native Method) #-15 java.net.URLClassLoader.findClass(Unknown Source) #-14 java.lang.ClassLoader.loadClass(Unknown Source) #-13 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) #-12 java.lang.ClassLoader.loadClass(Unknown Source) #-11 java.lang.Class.forName0(Native Method) #-10 java.lang.Class.forName(Unknown Source) #-9 php.java.bridge.Util.classForName(Util.java:1518) #-8 php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-7 php.java.bridge.Request.handleRequest(Request.java:458) #-6 php.java.bridge.Request.handleRequests(Request.java:500) #-5 php.java.bridge.JavaBridge.handleRequests(JavaBridge.java:150) #-4 php in /usr/share/apache-tomcat-7.0.55/webapps/JavaBridge/java/Java.inc on line 195

Is this set-up even correct? Are the jar files and php files located in correct directories? How can this error be resolved?

4

1 回答 1

1

我有一个类似的问题,我认为你的 php 文件编码正确。你需要做的是:

sudo chown yourprofile:yourprofile -R TOMCAT.HOME/webapps/JavaBridge/WEB-INF/lib/cfa.jar

使用此命令重新启动您的 tomcat 服务器shutdown.sh,然后使用startup.sh 重新启动 apache 网络服务器sudo service apache2 restart

确保 php 文件中的命令实际上与 jar 文件中的类名完全相同,并且路径也正确。

我同意鲍里斯的观点,$address = new Java('com.odus.apg.cfa.java.address');实际上应该是这样的$address = new Java('com.odus.apg.cfa.java.Address');

问题有时可能与权限有关,而不是路径、命名等。

于 2014-12-09T13:40:53.293 回答