Java 小程序与 init() 位于包中?
我想知道您是否可以将主类(或具有 init 方法的类,等等)放入包中,并且仍然让它在浏览器中运行? 大多数时候我把我的小程序放入(默认包)中,但是我这里的小程序是在一个包中,那么我仍然可以将它嵌入到网页中吗?
我用谷歌搜索了一下,结果很少。 假设我在名为 MyApp.jar
的 jar 文件中名为 app
的目录中找到了 MyApplet.class
。
我尝试过这些但没有成功:
<applet archive="MyApp.jar" code="MyApplet.class">
<applet archive="MyApp.jar" code="app/MyApplet.class">
<applet archive="MyApp.jar" code="/app/MyApplet.class">
<applet archive="MyApp.jar/app/" code="MyApplet.class">
<applet archive="MyApp.jar" codebase="app/" code="MyApplet.class">
每个都给我一个 ClassNotFoundException。
提前致谢。
I'm wondering if you can put the main class (or the class with the init method, whatever) inside a package and still have it run in a browser? Most of the time I put my applets into the (default package) but my applet here is in a package, so can I still embed it into the webpage?
I've googled it with little results. Say I've got MyApplet.class
in a directory called app
in the jar file called MyApp.jar
.
I've tried these with no success:
<applet archive="MyApp.jar" code="MyApplet.class">
<applet archive="MyApp.jar" code="app/MyApplet.class">
<applet archive="MyApp.jar" code="/app/MyApplet.class">
<applet archive="MyApp.jar/app/" code="MyApplet.class">
<applet archive="MyApp.jar" codebase="app/" code="MyApplet.class">
Each of these gives me a ClassNotFoundException.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
archive属性应包含jar的文件名,并且应放置在与网页相同的目录中。
code 属性中的类文件应包含由正斜杠分隔的完全限定类名,以指示目录结构。
因此,在您尝试的试验列表中,试验 2 应该会成功,前提是 MyApp.jar 实际上存在于 html 页面旁边。 此外,MyApp.jar 应在根目录中包含“app”目录,其中应包含 MyApplet 类文件。 不要忘记在应用程序包中包含 MyApplet 类本身。
您可以查看此页面参考。
The archive attribute should contain the file name of the jar, and it should be placed in the same directory as the web page.
The class file in the code attribute should contain the fully qualified class name separated by forward slashes to indicate the directory structure.
Therefore, in your list of trials attempted, trial 2 should succeed, provided that MyApp.jar is actually present along side the html page. Additionally, MyApp.jar should contain the 'app' directory in the root, which should contain the MyApplet classfile. Don't forget to have MyApplet class itself in the app package.
You could take a look at this page for reference.
好吧,您以点线形式列出了包,并且没有将“.class”放在末尾。
Well you list the package in a dotted form and you don't put the '.class' on the end.
我不确定,但你试过这样吗?:
I'm not sure, but have you tried like this?: