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?

5
  • Are you sure this is a class: com.odus.apg.cfa.java.address? It looks like a package to me. Commented Sep 17, 2014 at 13:46
  • the class file address.class in inside of cfa.jar Commented Sep 17, 2014 at 13:56
  • Okay. Classes in Java should be in PascalCase - so Address. But that isn't the problem, it's just (very) confusing. Commented Sep 17, 2014 at 14:10
  • It seems that php file is unable to locate the cfa.jar Is there any syntax in java to reference these jar files Commented Sep 17, 2014 at 14:38
  • just a tomcat restart fixed the problem in my case, as tomcat/java Bridge indexes jars on startup Commented Nov 6, 2015 at 10:48

1 Answer 1

1

I had a similar problem, I think your php file is correctly coded. What you need to do is this :

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

After this command restart your tomcat server using shutdown.sh and then startup.sh Also, restart the apache webserver using sudo service apache2 restart

Ensure that the command in the php file is actually exactly in the same case as per the class names in the jar file and path is also correct.

I agree with Boris that $address = new Java('com.odus.apg.cfa.java.address'); should actually be something like $address = new Java('com.odus.apg.cfa.java.Address');

The problem can be sometimes with the permissions rather than the path, naming etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.