1

我已经在 netbeans tomcat 目录中设置了 PHP/Java Bridge 和工作示例。使用自定义 JAR 不起作用这是我的代码:

package com.micha;

public class Hello1Bean {
    public Hello1Bean()
    {}
    String hi() {return "This is my hello message";}
    String hello(String name) {return "Hello" + name;}
}

和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");
        $world = new Java("com.micha.Hello1Bean");
        echo java_values($world->hi());
        echo "Hello Working Thingy\n\n";

        ?>
    </body>
</html>

当我检查时http://localhost:8084/JavaBridge/mytest.php

    javax.servlet.ServletException: java.lang.RuntimeException: PHP Fatal error:  Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:Hello1Bean]]->hi. Cause: java.lang.NoSuchMethodException: hi(). Candidates: [] VM: 1.6.0_25@http://java.sun.com/" at:
#-6 php.java.bridge.JavaBridge.checkM(JavaBridge.java:1085)
#-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1024)
#-4 php.java.bridge.Request.handleRequest(Request.java:417)
#-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 C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(2, 'com.micha.Hello...', 'T', true)
#1 C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc(360): java_Arg->getResult(true)
#2 C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc(366): java_Client->getWrappedResult(true)
#3 C:\Users\Micha\.netbean in C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\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:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    php.java.servlet.PhpCGIFilter.doFilter(PhpCGIFilter.java:126)

在我有一个 ClassNotFoundException 之前,它知道有一个类,但由于某些奇怪的原因,我无法调用该函数。(如果我com.micha.Hello1Bean用一些不存在的类替换“”,那么我会得到那个异常)

4

1 回答 1

2

您的方法不公开,请尝试:

public String hi() {
       return "This is my hello message";
}
于 2012-06-11T14:06:06.793 回答