java - 使用 PHP/Java 桥接器时排除 ClassNotFoundException 故障

标签 java php

我已按照本教程 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 Java standalone or Java webapps documents.

关于java - 使用 PHP/Java 桥接器时排除 ClassNotFoundException 故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11829265/

相关文章:

java - 使用新数据集刷新的 JFreeChart XY 图表?例子?

java - spring mvc 中基于注解的 Controller 的依赖注入(inject)

php - 为 WORDPRESS 导入表时出错(位置 25 附近的 "ON")(外键错误)

php - 用于缩短文本的 Twig 扩展?

php - 交换数组中的两个键/值对

java - DynamoDB 中的 RateLimited 写入

java - 如何使Spring Controller 在所有请求主体传输之前被调用(并将主体作为流处理)?

java - 使用媒体播放器或音池在 fragment 内的 onClick 中播放声音

php - 如何从php访问ajax返回的数据?

php - 集成 PHP、SSH 和 ssh-agent