简体   繁体   English

Java小程序将无法正常工作

[英]java applet won't work

this is homework stuff, but the question is not much about coding. 这是家庭作业,但是问题不关编码。 the task is to write a java applet to work on an m-grid server. 任务是编写一个Java applet在m-grid服务器上工作。 i have the server running on apache. 我的服务器在apache上运行。 it has a few sample applets in .jar and .class form. 它具有.jar和.class形式的一些示例小程序。 the .class versions work; .class版本有效; the .jar versions work on appletviewer, but they break if I submit them as a job to the server with this: .jar版本可以在appletviewer上运行,但是如果我将其作为作业提交给服务器,则它们会中断:

load: class examples/pixelcount/PixelCount.class not found.
java.lang.ClassNotFoundException: examples.pixelcount.PixelCount.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: examples.pixelcount.PixelCount.class

I'm not really sure where exactly is the problem in here, given that they work on appletviewer. 考虑到它们在appletviewer上运行,我不确定在这里的问题到底在哪里。 any help would be appreciated.. 任何帮助,将不胜感激..

EDIT: 编辑:

don't know if I wrote it clearly. 不知道我是否写清楚。 by ".class version" i refer to html file with this content: 通过“ .class版本”,我引用具有以下内容的html文件:

<applet height="300" width="450" code="examples/pixelcount/PixelCount.class"></applet>

and ".jar" with this content: 以及带有以下内容的“ .jar”:

<applet height="300" width="450" archive="PixelCount.jar" code="examples.pixelcount.PixelCount.class"></applet>

EDIT2: 编辑2:

the mentioned example jar file can be found here 提到的示例jar文件可以在这里找到

The PixelCount class is not packaged in your jar I think. 我认为PixelCount类未打包在您的jar中。

And as the error is Caused by: java.net.ConnectException: Connection refused: connect it might be that it tried to obtain that class from the net somewhere, and the location does not match or a proxy is in between. 并且由于错误是Caused by: java.net.ConnectException: Connection refused: connect原因Caused by: java.net.ConnectException: Connection refused: connect可能是因为它试图从某个地方的网络中获取该类,并且位置不匹配或之间存在代理。

EDIT 编辑

You do have the archive someplace the m-server, whatever that may be, can find it? 您确实在M服务器的某个地方有档案,可以找到它吗? See the Java Applet Tag ref. 请参阅Java Applet标签参考。 docs . docs You may need something like 您可能需要类似

CODEBASE = codebaseURL
This OPTIONAL attribute specifies the base URL of the applet--the directory 
that contains the applet's code. If this attribute is not specified, then the 
document's URL is used.

The CODE is relative to the base URL of the document which holds the applet tag. CODE相对于保存applet标签的文档的基本URL。 If you want to override that you might need that CODEBASE parameter. 如果要覆盖,则可能需要该CODEBASE参数。

它找不到文件PixelCount.class,它不在目录examples / pixlecount中,这就是发生此错误的原因。

Don't include the .class extension in the code attribute. 不要在code属性中包含.class扩展名。

examples.pixelcount.PixelCount is the name of the class . examples.pixelcount.PixelCount该类的名称。
examples.pixelcount.PixelCount.class is the name of the file that contains the class. examples.pixelcount.PixelCount.class是包含该类的文件的名称。

The code attribute should read 代码属性应显示为

code="examples.pixelcount.PixelCount"

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

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