小程序的烦恼
我正在尝试在我的网站中嵌入一个小程序,但看在上帝的份上,我无法弄清楚为什么这行不通!我有一个名为 BHSurveyor.jar
的 JAR 文件,其中的类扩展了 bhs.gui.GUIApplet
中的 javax.swing.JApplet
。现在,我已经尝试将它嵌入到页面中,并且我已经尝试了从
<applet codebase="/dist/" archive="/dist/BHSurveyor.jar" code="bhs.gui.GUIApplet" width="256px" height="256px" />
(在 JAR 下一级文件夹级别的本地打开的 HTML 文件中)到
<applet codebase="file://localhost/C:/Users/Supuhstar/Documents/NetBeansProjects/BHSurveyor/dist/" archive="file://localhost/C:/Users/Supuhstar/Documents/NetBeansProjects/BHSurveyor/dist/BHSurveyor.jar" code="bhs.gui.GUIApplet.class" width="256px" height="256px" />
其所有排列,然后是一些......但是每一次,我收到相同的红色“错误。单击了解详细信息”消息(未提供任何详细信息)。 有人可以告诉我在这里做什么吗?
我的设置
可以在 http://s.supuhstar.operaunite.com/s/content/test/
测试
按照建议,我跑了
jar -tvf BHSurveyor.jar
'jar' is not recognized as an internal or external command,
operable program or batch file.
假设他们意味着别的东西,我尝试了
java -jar -tvf BHSurveyor.jar
Unrecognized option: -tvf
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
所以你看这并不没有帮助...再次,逃离假设,我运行了这个并得到了我希望的预期输出:
"C:\Program Files\Java\jdk1.7.0\bin\jar" -tvf BHSurveyor.jar
0 Mon Aug 29 11:56:10 EDT 2011 META-INF/
228 Mon Aug 29 11:56:08 EDT 2011 META-INF/MANIFEST.MF
0 Mon Aug 29 11:56:10 EDT 2011 bhs/
0 Mon Aug 29 11:56:10 EDT 2011 bhs/gui/
2264 Mon Aug 29 11:56:08 EDT 2011 bhs/AnswerType.class
1851 Mon Aug 29 11:56:08 EDT 2011 bhs/DefPage.class
1965 Mon Aug 29 11:56:10 EDT 2011 bhs/DefQuestion.class
1463 Mon Aug 29 11:56:10 EDT 2011 bhs/DefTitlePage.class
1338 Mon Aug 29 11:56:10 EDT 2011 bhs/Main.class
615 Mon Aug 29 11:56:08 EDT 2011 bhs/Page.class
786 Mon Aug 29 11:56:10 EDT 2011 bhs/Question.class
402 Mon Aug 29 11:56:10 EDT 2011 bhs/TitlePage.class
1757 Mon Aug 29 11:56:10 EDT 2011 bhs/Utils$1.class
766 Mon Aug 29 11:56:10 EDT 2011 bhs/Utils$2.class
6188 Mon Aug 29 11:56:10 EDT 2011 bhs/Utils.class
3409 Mon Aug 29 11:56:10 EDT 2011 bhs/gui/GUIApplet.class
1218 Mon Aug 29 11:56:10 EDT 2011 bhs/gui/GUIJFrame.class
3549 Mon Aug 29 11:56:10 EDT 2011 bhs/gui/GUIPage.class
824 Mon Aug 29 11:56:10 EDT 2011 bhs/gui/GUIQuestion$1.class
8650 Mon Aug 29 11:56:10 EDT 2011 bhs/gui/GUIQuestion.class
Applet 构造函数和 init
public GUIApplet(Page... pgs)// throws UnknownHostException
{
System.out.println("new GUIApplet(Page... " + pgs + ")");
// System.out.println(java.net.InetAddress.getLocalHost().getHostAddress());
System.out.println(" setting layout...");
setLayout(new java.awt.GridBagLayout());
System.out.println(" adding components...");
addComponents();
System.out.println(" initializing pages...");
pages = new ArrayPP<>();
System.out.println(" installing pages...");
int i=1;
for (Page p : pgs)
if (p != null)
installPage(p);
System.out.println(" changing look-and-feel...");
LookAndFeelChanger.setLookAndFeel(LookAndFeelChanger.NIMBUS);
System.out.println(" fixing nav buttons...");
fixNavButtons();
System.out.println("GUIApplet complete");
}
public void init()
{
// TODO start asynchronous download of heavy resources
System.out.println("GUIApplet.init()");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将其更改为..
注意:根据我的统计,这 2 个
applet
元素之间有 5 个差异。代码库
对代码库绝对路径的一些仔细检查促使我做出进一步的评论。
我怀疑是否存在如图所示的路径。将其复制/粘贴到浏览器地址栏中,然后按 Enter 键(对于基于文件的路径始终是一个很好的“严格测试”)。
你得到目录列表了吗?
我怀疑它应该是:
file:///C:/Users/Supuhstar/Documents/NetBeansProjects/BHSurveyor/dist/
(即没有
localhost
)。代码库或类似路径中的初始
/
也具有特殊意义。它相当于“网站的根”。这意味着您的/dist/
的其他代码库实际上会指向file:///C:/dist/
您会得到什么结果浏览器中的该路径?
顺便说一句 - 这些问题都不是反问。为了最好地帮助你,我需要答案。
测试页面更新
看起来好像 BHSurveyor.jar 包含文本,至少是 返回内容类型
text/html
。并且控制台非常有帮助..在本地测试中更新小程序
在本地下载 Jar 后(遇到不同的错误,然后安装 JDK 7 来修复它),我终于能够看到您所描述的内容了。
init()
方法中是否有任何 try/catch 语句?小程序是否有(非默认)构造函数?如果是这样,请重新尝试/捕获相同的问题。init()
和构造函数部分的代码(复制/粘贴)是什么?我的最新理论(关于小程序加载的主要问题)是,有
try
/catch
语句吞并或忽略异常。除此之外,我不知道为什么小程序无法加载,但在 Java 控制台中没有显示任何相关输出。顺便说一句,服务器返回 Jar 的错误内容类型的事实应该得到修复,尽管这似乎不是这里的根本问题。
Change that to..
Note: By my count there are 5 differences between those 2
applet
elements.Codebase
Some close examination of that codebase absolute path prompted me to make further comments.
I doubt there is any such path as shown. Copy/paste it into a browser address bar and hit enter (always a good 'acid test' for file based paths).
Do you get the directory listing?
I suspect it should be:
file:///C:/Users/Supuhstar/Documents/NetBeansProjects/BHSurveyor/dist/
(i.e. without
localhost
).There is also a special significance to the initial
/
in a codebase or similar path. It equates to 'the root of the site'. That means that your other codebase of/dist/
would actually point tofile:///C:/dist/
What result do you get for that path in the browser?
BTW - neither of those questions are rhetorical. To best help you, I need answers.
Update on test page
It appears as though BHSurveyor.jar contains text, at least it is returning a content-type of
text/html
. And the console is being very helpful..Update on applet in local testing
After downloading the Jar locally, (encountering a different error, then installing JDK 7 to fix it), I am finally in a position to see what you described.
init()
method? Does the applet have a (non-default) constructor? If so, same question re try/catch.init()
and constructor parts of the applet source?My latest theory (as to the primary problem with the applet loading) is that there are
try
/catch
statements that are swallowing or ignoring exceptions. Beyond that, I am at a loss as to why the applet would not load, yet not show any relevant output in the Java Console.As an aside, the fact that the server is returning the wrong content-type for the Jar should be fixed, though it seems it is not the underlying problem here.
你犯了几个错误。
archive
必须与代码库相关。这意味着如果您的 jar 位于dist
文件夹下,您应该说:.class
后缀,因此在您的情况下写入: code="bhs.gui.GUIApplet.class" (正如您在第二个示例中所做的那样,其中 codebase 和 archive虽然px
:width="256" height =“256”
使用小程序控制台。您可能会看到某种异常,这将帮助您了解问题所在,
请使用以下
祝你好运。
You did several mistakes.
archive
is must be relative to codebase. It means that if your jar is underdist
folder you should say:<applet codebase="/dist/" archive="BHSurveyor.jar"
or<applet codebase="/" archive="/dist/BHSurveyor.jar"
(unless your jar is actually under/dist/dist/BHSurveyor.jar
).class
suffix in the value of code attribute, so in your case write: code="bhs.gui.GUIApplet.class" (as you did in second example where codebase and archive seem to be completely wrong.px
:width="256" height="256"
Use Applet console. It can be started from menu of your browser. Probably you will see some kind of exception there that will help you to understand what the problem is.
If all this does not help, do the following.
appletviewer
or using your IDE. Be sure that it is able to run.Good luck.
您在查看 Java 控制台吗?例如,在 IE 中:工具 -> Internet 选项 -> 高级,您将看到启用控制台的选项。您可能会在那里看到一些有用的错误消息。
Are you looking in the Java console? For example in IE: Tools->Internet Options->Advanced you'll see an option to enable the console. You may well see some useful error messages there.