加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

使用PHP / Java桥时对ClassNotFoundException进行故障排除

发布时间:2020-12-13 13:46:48 所属栏目:PHP教程 来源:网络整理
导读:我已经按照本教程 http://www.dsl.uow.edu.au/~sk33/php5java.htm,但最后我尝试了这个 ?phpjava_require('http://localhost/test/HelloWorld.jar');$myObj = new Java('HelloWorld');// display Hello Worldecho (String) $myObj-getHelloWorld();? 我得到了
我已经按照本教程 http://www.dsl.uow.edu.au/~sk33/php5java.htm,但最后我尝试了这个
<?php

java_require('http://localhost/test/HelloWorld.jar');
$myObj = new Java('HelloWorld');

// display Hello World
echo (String) $myObj->getHelloWorld();


?>

我得到了这个例外

PHP Fatal error: Uncaught [o(Exception):”java.lang.Exception: CreateInstance failed:new HelloWorld. Cause: java.lang.ClassNotFoundException: Could not find HelloWorld in java_require() path. Please check the path and the SEL and File permissions. Responsible VM: 1.5.0_14@http://java.sun.com/” at:#-10 php java.bridge.DynamicJavaBridgeClassLoader.loadClass(DynamicJavaBridgeClassLoader.java:293)

您所关注的教程已有5年历史,根据 FAQ,不推荐使用java_require():

Why has java_require() been deprecated?

Because Java doesn’t have a module system.

For example a library “lucene-2.3.1.jar” required by application B,cannot be loaded if an older version of the library,required by application A,is already cached.
An attempt to link the library anyway will cause “NoClassDefFound” or “NoSuchMethod” errors at runtime. Or some procedures may throw checked exceptions even though they haven’t declared them.

To protect PHP developers from Java’s “jar hell”,I have removed the dynamic class loading mechanism from PHP/Java Bridge version 6.0; java_require() issues a warning.

A proper Java module system must use special Java VM hooks,which don’t exist until now.

How do I load Java libraries?

You should link your Java application as described in the 07001 or 07002 documents.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读