Java 小程序与 init() 位于包中?

发布于 2024-07-14 21:08:13 字数 657 浏览 2 评论 0原文

我想知道您是否可以将主类(或具有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

护你周全 2024-07-21 21:08:13

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.

黯然 2024-07-21 21:08:13

好吧,您以点线形式列出了包,并且没有将“.class”放在末尾。

<applet code="packagefolder1.packagefolder2.MyApplet" archive="folder1/folder2/MyApp.jar">

</applet>

Well you list the package in a dotted form and you don't put the '.class' on the end.

<applet code="packagefolder1.packagefolder2.MyApplet" archive="folder1/folder2/MyApp.jar">

</applet>
著墨染雨君画夕 2024-07-21 21:08:13

我不确定,但你试过这样吗?:

<applet archive="MyApp.jar" code="MyApplet">

I'm not sure, but have you tried like this?:

<applet archive="MyApp.jar" code="MyApplet">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文