简体   繁体   English

Java从Eclipse的Applet导出jar错误

[英]Java export jar from eclipse applet error's

So I have created an applet in Java, and would like to export it as a jar, then attach it to a webpage. 因此,我已经用Java创建了一个applet,并希望将其导出为jar,然后将其附加到网页上。

<applet
alt = "Dynamic Tree Applet Demo"
code = 'image.Main'
archive = 'Main.jar',
width = 300,
height = 300 />

This is basically my html code. 这基本上是我的html代码。 The jar was exported from ecplise. 罐子是从ecplise出口的。 Everything is in a package image. 一切都在包装图像中。 There is a public static void main, in the java file that runs the applet, not sure if that is even needed. 运行小程序的java文件中有一个公共的静态void主程序,不确定是否甚至需要这样做。

However, when I create either a regular or a runnable jar, I get lots of errors.. 但是,当我创建常规或可运行的jar时,会出现很多错误。

With a regular jar, and thus no main set in the manifest: 使用常规的jar,因此清单中没有主要的设置:

load: class image.Main not found.
java.lang.ClassNotFoundException: image.Main
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.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.io.FileNotFoundException: C:\Users\Daniel\Desktop\ImageCapture\New folder\image\Main.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(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)
... 9 more

Exception: java.lang.ClassNotFoundException: image.Main 异常:java.lang.ClassNotFoundException:image.Main

I get the same error when using a runnable jar, exported from eclipse, which doesn't run, by the way. 顺便说一句,当使用从eclipse导出但无法运行的可运行jar时,我遇到了相同的错误。 The jar does absolutely nothing when double clicked, not even the main-class missing error. 双击该jar绝对不会执行任何操作,甚至不会丢失主要类错误。

The manifest has the proper main-class setup when using the runnable jar, image.Main. 使用可运行的jar image.Main时,清单具有正确的主类设置。

The classpath in that instance is just : . 该实例中的类路径就是:。

Thanks in advance, hope my information was detailed enough. 在此先感谢您,希望我的信息足够详细。

Applet should use public void init() as entry point, and not the public static void main . Applet应该使用public void init()作为入口点,而不是public static void main Export as jar file should be enough, don't export as runnable jar. 导出为jar文件应该足够,不要导出为可运行的jar。

1) The way you defined the applet tag, your Main.jar has to be in the same folder as the html page. 1)您定义applet标签的方式,Main.jar必须与html页面位于同一文件夹中。 Make sure it is. 确保是。

2) Make sure your exported jar contains the class file(s). 2)确保您导出的jar包含类文件。 You can use any zip explorer (WinZip, WinRAR, etc) to open the jar file and make sure there's a folder named image with a file named Main.class in it. 您可以使用任何zip浏览器(WinZip,WinRAR等)打开jar文件,并确保其中有一个名为image的文件夹,其中包含名为Main.class的文件。 You can also use the command 您也可以使用以下命令

jar -tf Main.jar

to list the contents of the jar file. 列出jar文件的内容。

3) Class and package names are case sensitive in Java, so make sure you have the correct case for both. 3)在Java中,类名和包名区分大小写,因此请确保两者的大小写均正确。

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

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