简体   繁体   English

我的课程路径出了什么问题?

[英]What's wrong with my classpath?

I'm trying to make an applet with jPCT. 我正在尝试用jPCT做一个applet。 Using jPCT requires that the jPCT jar be added to the classpath. 使用jPCT要求将jPCT jar添加到类路径。 I thought I had it, but I'm still getting a class not found exception about one of jPCT's classes. 我以为自己拥有了,但是我仍然得到一个关于jPCT类之一的类未被发现的异常。

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:

<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. 我正在使用Apache,并且已经验证可以从代码中的URL下载我的jar。

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? 我究竟做错了什么?

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

And you have to load your Applet into your web browser from the web server, not from the file system. 而且,您必须从Web服务器而不是从文件系统将Applet加载到Web浏览器中。

Here is the relevant reading materials. 这是相关的阅读材料。

ARCHIVE = archiveList 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. 使用具有给定CODEBASE的AppletClassLoader实例加载类。 The archives in archiveList are separated by ",". archiveList中的档案用“,”分隔。 NB: in JDK1.1, multiple APPLET tags with the same CODEBASE share the same instance of a ClassLoader. 注意:在JDK1.1中,具有相同CODEBASE的多个APPLET标记共享ClassLoader的相同实例。 This is used by some client code to implement inter-applet communication. 一些客户端代码使用它来实现小程序之间的通信。 Future JDKs may provide other mechanisms for inter-applet communication. 未来的JDK可能会提供其他的小程序间通信机制。 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. 这意味着archiveList中的档案必须与代码库位于同一目录或该子目录的子目录中。 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. ) 除非安全策略文件中明确允许,否则../a/b.jar格式的archiveList中的条目将不起作用(除非是http代码库,否则httpList中的ArchiveList必须与该代码库来自同一主机,但路径中可以包含“ ..”。

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

Example

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

Have you used any server like Tomcat ? 您是否使用过像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 . 如果有,则可能需要为其分配jar文件的路径,或将jpct.jar复制到tomcat / lib / dir。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM