我的类路径有什么问题吗?

发布于 2024-11-16 08:05:09 字数 2447 浏览 1 评论 0原文

我正在尝试用 jPCT 制作一个小程序。使用 jPCT 需要将 jPCT jar 添加到类路径中。我以为我已经找到了,但我仍然收到有关 jPCT 类之一的未找到类异常。

我的命令:

$ javac -classpath /var/www/html/jpct.jar:.  /var/www/html/HelloWorld.java
$ jar cf /var/www/html/HelloWorld.jar /var/www/html/HelloWorld.class

我的 HTML:

<html>
    <head>
        <title>Hello World</title>
    </head>
    <body>
        <applet code="HelloWorld"
              width=640
              height=480
              archive="http://applet/HelloWorld.jar,http://applet/jpct.jar">
        </applet>
    </body>
</html>

我正在使用 Apache,并且我已经验证我的 jar 可以从我的代码中的 URL 下载。

确切的错误消息:

$ firefox http://applet/HelloWorld.html
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1)
OpenJDK Server VM (build 20.0-b11, mixed mode)

(firefox-bin:15296): LIBDBUSMENU-GTK-CRITICAL **: dbusmenu_menuitem_property_set_shortcut: assertion `gtk_accelerator_valid(key, modifier)' failed
Unable to use Firefox's proxy settings. Using "DIRECT" as proxy type.
java.lang.NoClassDefFoundError: com/threed/jpct/World
    at HelloWorld.init(HelloWorld.java:18)
    at sun.applet.AppletPanel.run(AppletPanel.java:436)
    at net.sourceforge.jnlp.NetxPanel.run(NetxPanel.java:69)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: com.threed.jpct.World
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at net.sourceforge.jnlp.runtime.JNLPClassLoader$CodeBaseClassLoader.findClass(JNLPClassLoader.java:1348)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    ... 4 more
Exception in thread "TimerQueue" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:155)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1262)
    at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:459)
    at java.util.concurrent.DelayQueue.take(DelayQueue.java:205)
    at javax.swing.TimerQueue.run(TimerQueue.java:167)
    at java.lang.Thread.run(Thread.java:679)

我做错了什么?

I'm trying to make an applet with jPCT. Using jPCT requires that the jPCT jar be added to the classpath. I thought I had it, but I'm still getting a class not found exception about one of jPCT's classes.

My commands:

$ javac -classpath /var/www/html/jpct.jar:.  /var/www/html/HelloWorld.java
$ jar cf /var/www/html/HelloWorld.jar /var/www/html/HelloWorld.class

My HTML:

<html>
    <head>
        <title>Hello World</title>
    </head>
    <body>
        <applet code="HelloWorld"
              width=640
              height=480
              archive="http://applet/HelloWorld.jar,http://applet/jpct.jar">
        </applet>
    </body>
</html>

I'm using Apache and I have verified that my jars are downloadable from the URLs in my code.

The exact error message:

$ firefox http://applet/HelloWorld.html
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1)
OpenJDK Server VM (build 20.0-b11, mixed mode)

(firefox-bin:15296): LIBDBUSMENU-GTK-CRITICAL **: dbusmenu_menuitem_property_set_shortcut: assertion `gtk_accelerator_valid(key, modifier)' failed
Unable to use Firefox's proxy settings. Using "DIRECT" as proxy type.
java.lang.NoClassDefFoundError: com/threed/jpct/World
    at HelloWorld.init(HelloWorld.java:18)
    at sun.applet.AppletPanel.run(AppletPanel.java:436)
    at net.sourceforge.jnlp.NetxPanel.run(NetxPanel.java:69)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: com.threed.jpct.World
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at net.sourceforge.jnlp.runtime.JNLPClassLoader$CodeBaseClassLoader.findClass(JNLPClassLoader.java:1348)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    ... 4 more
Exception in thread "TimerQueue" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:155)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1262)
    at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:459)
    at java.util.concurrent.DelayQueue.take(DelayQueue.java:205)
    at javax.swing.TimerQueue.run(TimerQueue.java:167)
    at java.lang.Thread.run(Thread.java:679)

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍景流年 2024-11-23 08:05:09

您必须将依赖项放在为 Applet .jar 文件提供服务的同一 Web 服务器上,并给出绝对位置或相对于 Applet 根上下文的位置。

并且您必须从 Web 服务器而不是文件系统将 Applet 加载到 Web 浏览器中。

这里是相关阅读材料。

ARCHIVE = archiveList

这个可选属性描述了一个
或更多包含类的档案
以及其他资源
“预加载”。类已加载
使用一个实例
AppletClassLoader 与给定的
代码库。 archiveList 中的档案
之间用“,”分隔。注意:在JDK1.1中,
多个APPLET标签具有相同的
CODEBASE 共享同一个实例
类加载器。这是被一些人使用的
实现小程序间的客户端代码
沟通。未来的 JDK 可能会提供
小程序间的其他机制
沟通。 出于安全原因,
小程序的类加载器可以读取
仅来自相同的代码库
小程序已启动。这意味着
archiveList 中的档案必须是
在同一目录中,或者在
代码库的子目录。参赛作品
在 ../a/b.jar 形式的 archiveList 中
除非明确说明,否则不会起作用
安全策略中允许的
文件(http 的情况除外)
代码库,档案所在
archiveList必须来自同一主机
作为代码库,但可以有“..”
在他们的道路上。
)

如果您的小程序位于 /var/www/html/Applet.jar 那么最简单的方法是将您的依赖项放在完全相同的位置 / var/www/html/jcpt.jar 然后你就可以引用它,而不必担心计算相对路径。

示例

    <applet code="HelloWorld"
          width=640
          height=480
          archive="HelloWorld.jar,jpct.jar">
    </applet>

You have to put your dependencies on the same web server that is serving the Applet .jar file and give the locations either absolutely or relative to the root context of the Applet.

And you have to load your Applet into your web browser from the web server, not from the file system.

Here is the relevant reading materials.

ARCHIVE = archiveList

This OPTIONAL attribute describes one
or more archives containing classes
and other resources that will be
"preloaded". The classes are loaded
using an instance of an
AppletClassLoader with the given
CODEBASE. The archives in archiveList
are separated by ",". NB: in JDK1.1,
multiple APPLET tags with the same
CODEBASE share the same instance of a
ClassLoader. This is used by some
client code to implement inter-applet
communication. Future JDKs may provide
other mechanisms for inter-applet
communication. For security reasons,
the applet's class loader can read
only from the same codebase from which
the applet was started. This means
that archives in archiveList must be
in the same directory as, or in a
subdirectory of, the codebase. Entries
in archiveList of the form ../a/b.jar
will not work unless explicitly
allowed for in the security policy
file (except in the case of an http
codebase, where archives in
archiveList must be from the same host
as the codebase, but can have ".."'s
in their paths.
)

if your applet is at /var/www/html/Applet.jar then the simplest thing to do is put your dependencies in the exact same location /var/www/html/jcpt.jar and then you can just refer to it without having to worry about calculating the relative path.

Example

    <applet code="HelloWorld"
          width=640
          height=480
          archive="HelloWorld.jar,jpct.jar">
    </applet>
傲鸠 2024-11-23 08:05:09

你用过Tomcat之类的服务器吗?如果有,您可能需要为其分配 jar 文件的路径或将 jpct.jar 复制到 tomcat/lib/ dir 。

Have you used any server like Tomcat ? If you have, you may need to assign the path of your jar file to it or copy the jpct.jar to the tomcat/lib/ dir .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文