I need to run some java code on php so I found this
http://php-java-bridge.sourceforge.net/pjb/index.php
so I downloaded tomcat and put the JavaBridge.war in the webapps directory and I got the examples working (It took me a while to figure this out)
I can even load built-in java stuff Java("java.lang.System")
and run the example jars with my own PHP code.
What I couldn't do was make my own jar and run it I tried a variety of different compilers (Eclipse,Netbeans,command-line) but this didn't help.
I'm trying to do something like this http://www.developer.com/java/other/php-with-java-using-php-java-bridge-tutorial.html
Here is my java code:
package m1sk;
/**
*
* @author M1sk
*/
public class Hello implements java.io.Serializable{
String hi() {return "This is my hello message";}
String hello(String name) {return "Hello" + name;}
}
php code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
require_once ("java/Java.inc");
// $t1 = new Java("java.lang.System");
//echo $t1->getProperties(); //this works
$world = new java("m1sk.Hello");
// echo $world->hi();
echo "Hello Working Thingy\n\n";
?>
</body>
</html>
i put the jar in ...\tomcat\webapps\JavaBridge\WEB-INF\lib and the php file in ...\tomcat\webapps\JavaBridge
and i get the following error when i test http://localhost:8080/JavaBridge/mytest.php
:
javax.servlet.ServletException: java.lang.RuntimeException: PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new m1sk.Hello. Cause: java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class m1sk.Hello) VM: 1.5.0_20@http://java.sun.com/" at:
#-13 org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1854)
#-12 org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
#-11 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
#-10 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
#-9 java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
#-8 java.lang.Class.forName0(Native Method)
#-7 java.lang.Class.forName(Class.java:242)
#-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.C in C:\xampp\tomcat\webapps\JavaBridge\java\Java.inc on line 195
php.java.servlet.fastcgi.FastCGIServlet.handle(FastCGIServlet.java:499)
php.java.servlet.fastcgi.FastCGIServlet.doGet(FastCGIServlet.java:521)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
php.java.servlet.PhpCGIFilter.doFilter(PhpCGIFilter.java:126)
I search the stack found this for my error: What is the reason for UnsupportedClassVersionError?
C:\Users\M1sk\Desktop>java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
C:\Users\M1sk\Desktop>javac -version
javac 1.6.0_25
the version are different but this should still work so I don't believe this is my problem