我正在尝试运行 Robert LaFore 所著的旧书“Java 中的算法和数据结构”中的一些旧 Java 小程序。
https://sites.fas.harvard.edu/~cscie119/resources/lafore/
或者
https://cs.brynmawr.edu/Courses/cs206/spring2004/lafore.html
我安装了 JDK 1.8 / Java 8,它包含 appletviewer.exe C:\Program Files\Java\jdk1.8.0_251\bin\appletviewer.exe
我根本不记得有人会如何操作它们。
我的路径中有 appletviewer.exe。
C:\aaa>path=%path%;C:\Program Files\Java\jdk1.8.0_251\bin
C:\aaa>appletviewer
Usage: appletviewer <options> url(s)
where <options> include:
-debug Start the applet viewer in the Java debugger
-encoding <encoding> Specify character encoding used by HTML files
-J<runtime flag> Pass argument to the java interpreter
The -J option is non-standard and subject to change without notice.
C:\aaa>wget https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.class
--2020-05-19 07:00:11-- https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.class
Resolving cs.brynmawr.edu (cs.brynmawr.edu)... 165.106.10.107
Connecting to cs.brynmawr.edu (cs.brynmawr.edu)|165.106.10.107|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3967 (3.9K) [application/octet-stream]
Saving to: 'Array.class'
Array.class 100%[=======================================================================>] 3.87K --.-KB/s in 0s
2020-05-19 07:00:11 (18.7 MB/s) - 'Array.class' saved [3967/3967]
C:\aaa>dir Array.class
Volume in drive C has no label.
Volume Serial Number is 4645-5DCE
Directory of C:\aaa
03/01/2005 15:59 3,967 Array.class
1 File(s) 3,967 bytes
0 Dir(s) 335,436,058,624 bytes free
C:\aaa>wget https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.java
--2020-05-19 07:00:24-- https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.java
Resolving cs.brynmawr.edu (cs.brynmawr.edu)... 165.106.10.107
Connecting to cs.brynmawr.edu (cs.brynmawr.edu)|165.106.10.107|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2020-05-19 07:00:25 ERROR 404: Not Found.
C:\aaa>appletviewer Array.class
C:\aaa>appletviewer Array
I/O exception while reading: C:\aaa\Array (The system cannot find the file specified)
C:\aaa>
作为我刚刚尝试的另一条路线https://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./ Mozilla Firefox,便携版 2.0.0.8 2007-10-22
但 Firefox 没有自带该插件,无法安装
添加
回去尝试使用 appletviewer,我通过谷歌搜索该错误发现,appletviewer 需要在给定 HTML 文件的情况下运行。
所以我尝试了
C:\aaa>wget https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.html
我得到了
C:\aaa>Appletviewer Array.html
java.lang.NoClassDefFoundError: personGroup
at Array.init(Array.java:746)
at sun.applet.AppletPanel.run(AppletPanel.java:434)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: personGroup
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:219)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 3 more
我尝试了 jd-gui-windows-1.6.6 并打开了 Array.class,我发现它有
private personGroup thePersonGroup;
在此 URL
https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/....
毫无疑问,这是对文件系统的引用
有Chap02/Array/Array.html
, Chap02/Array/Array.class
但我看不到任何 personGroup.class 或 personGroup.java
答案1
您只下载了 Array.class,即“启动类”。但是,此类会加载位于同一目录中的其他类。例如,该类personGroup
也位于此目录中:
https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/personGroup.class
因此,除非您下载了所有相关的课程,否则您必须下载每个课程中链接的每个课程。
由于 Web 服务器拒绝文件夹列表,因此您必须逐个识别并下载每个类。
NoClassDefFoundError
下一步要下载的类在您将获得的异常中可见。
答案2
我将保留所接受的答案。
为我解决问题的关键就是这个案例!
必须正确处理案件
https://cs.brynmawr.edu/Courses/cs206/spring2004/lafore.html
https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.html
并且已经完成了
C:\aaa>path=%path%;C:\Program Files\Java\jdk1.8.0_251\bin
C:\aaa\fff>appletviewer Array.html 加载:未找到类 Array.class。...
wget https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/Array.class
C:\aaa\fff\ff>appletviewer Array.html
java.lang.NoClassDefFoundError: personGroup
请注意,该类的 p 是小写的!与具有大写 A 的数组类不同!
wget https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/personGroup.class
C:\aaa\fff\ff>appletviewer Array.html
java.lang.NoClassDefFoundError: person
该类的首字母再次小写
wget https://cs.brynmawr.edu/Courses/cs206/spring2004/WorkshopApplets/Chap02/Array/person.class
然后一切就开始了
所以,他们拥有的 Web 服务器区分大小写。appletviewer 在显示文件名时会考虑大小写。这很好。不幸的是,据我所知,该程序没有遵循任何一致的命名类文件的大小写,因为它有 Array.class、person.class 和 personGroup.class,所以这是一种混合。我不知道这是否是任何标准惯例,可能是。但我不知道。