简体   繁体   English

PHP / Java Bridge UnsupportedClassVersionError

[英]PHP/Java Bridge UnsupportedClassVersionError

I need to run some java code on php so I found this 我需要在php上运行一些Java代码,所以我发现了这一点

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) 所以我下载了tomcat并将JavaBridge.war放在webapps目录中,并使示例正常工作(花了一段时间才弄清楚了)

I can even load built-in java stuff Java("java.lang.System") and run the example jars with my own PHP code. 我什至可以加载内置的Java东西Java("java.lang.System")并使用自己的PHP代码运行示例jar。

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. 我无法做的是制作自己的jar并运行它,我尝试了各种不同的编译器(Eclipse,Netbeans,命令行),但这无济于事。

I'm trying to do something like this http://www.developer.com/java/other/php-with-java-using-php-java-bridge-tutorial.html 我正在尝试做这样的事情http://www.developer.com/java/other/php-with-java-using-php-java-bridge-tutorial.html

Here is my java code: 这是我的Java代码:

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: php代码:

<!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 我将罐子放在... \\ tomcat \\ webapps \\ JavaBridge \\ WEB-INF \\ lib中,并将php文件放在... \\ tomcat \\ webapps \\ JavaBridge中

and i get the following error when i test http://localhost:8080/JavaBridge/mytest.php : 当我测试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? 我搜索堆栈时发现了我的错误: 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 版本不同,但是仍然可以使用,所以我不认为这是我的问题

Reason for UnsupportedClassVersionError is because your class file was compiled using a later version of the JDK (eg. Java 7) while your JRE is an earlier version (eg. Java 6). 出现UnsupportedClassVersionError原因是因为您的类文件是使用更高版本的JDK(例如Java 7)编译的,而您的JRE是早期版本(例如Java 6)。

If you are using external libraries, then it is likely that the external library was compiled with a more recent version of the Java Compiler, as compared to the JRE you are using. 如果您使用的是外部库,则与使用的JRE相比,该外部库很可能是使用较新版本的Java Compiler进行编译的。 I would recommend you upgrade your JRE to the latest version. 我建议您将JRE升级到最新版本。

If you are using an Application Server to run it, do check that your Application Server is using the latest version of JRE as well. 如果您使用Application Server运行它,请检查您的Application Server是否也在使用最新版本的JRE。 Your environment variable may be pointing at the latest version of JRE, but your application server may not be doing the same. 您的环境变量可能指向最新版本的JRE,但您的应用程序服务器可能没有这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM