使用PHP / Java桥时对ClassNotFoundException进行故障排除 [英] Troubleshooting ClassNotFoundException when using PHP/Java bridge

查看:430
本文介绍了使用PHP / Java桥时对ClassNotFoundException进行故障排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照本教程 http://www.dsl.uow .edu.au / ~sk33 / php5java.htm ,但最后当我尝试这个时

I've followed this tutorial http://www.dsl.uow.edu.au/~sk33/php5java.htm, but at last when I tried this

<?php

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

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


?>

我得到了这个例外


PHP致命错误:未捕获[o(异常):java.lang.Exception:CreateInstance失败:新的HelloWorld。原因:java.lang.ClassNotFoundException:在java_require()路径中找不到HelloWorld。请检查路径以及SEL和文件权限。负责任VM:1.5.0_14@http://java.sun.com/at:# - 10 php java.bridge.DynamicJavaBridgeClassLoader.loadClass(DynamicJavaBridgeClassLoader.java:293)

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岁,根据常见问题解答 java_require()已弃用:

The tutorial you're following is 5 years old and, according to the FAQ, java_require() is deprecated:



为什么不推荐使用java_require()?

因为Java没有模块系统。

Because Java doesn't have a module system.

例如库luce应用程序B所需的ne-2.3.1.jar,如果已经缓存了应用程序A所需的旧版本库,则无法加载。
尝试链接库无论如何都会在运行时导致NoClassDefFound或NoSuchMethod错误。或者某些程序可能会抛出已检查的异常,即使它们尚未声明它们。

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.

为了保护PHP开发人员免受Java的jar hell,我删除了动态PHP / Java Bridge版本6.0中的类加载机制; java_require()发出警告。

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.

正确的Java模块系统必须使用特殊的Java VM挂钩,直到现在它才存在。

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

如何加载Java库?

您应按 Java standalone Java webapps 文档。


这篇关于使用PHP / Java桥时对ClassNotFoundException进行故障排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆