我创建了一个在Web浏览器上运行的简单applet。我通过在命令提示符下运行“C:\ Program Files \ Java \ jdk1.6.0_21 \ bin \ jar”cfv Project7Applet.jar * .class来创建Jar文件,然后当我尝试运行jar文件时,我得到“失败”加载主类清单属性错误“但我不明白为什么会发生这种情况,因为在我创建jar文件的命令提示符中它说
added manifest
adding: Project7Applet.class.....
adding: Project7Panel.class...
这是我的.html文件
<html>
<head>
<title>Right Triangles</title>
</head>
<body>
<h1>Right Triangles</h1>
<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<object
classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase = "http://java.sun.com/update/1.6.0/jinstall-6u21-windows-i586.cab#Version=6,0,0,7"
WIDTH = 240 HEIGHT = 175 >
<PARAM NAME = CODE VALUE = "Project7Applet.class" >
<PARAM NAME = ARCHIVE VALUE = "Project7Applet.jar" >
<param name = "type" value = "application/x-java-applet;version=1.6">
<param name = "scriptable" value = "false">
<comment>
<embed
type = "application/x-java-applet;version=1.6" \
CODE = "Project7Applet.class" \
ARCHIVE = "Project7Applet.jar" \
WIDTH = 200 \
HEIGHT = 125
scriptable = false
pluginspage = "http://java.sun.com/products/plugin/index.html#download">
<noembed>
<p>This applet requires version 1.5 or later of Java.</p>
</noembed>
</embed>
</comment>
</object>
<!--
<APPLET CODE = "Project7Applet.class" ARCHIVE = "Project7Applet.jar" WIDTH = 240 HEIGHT = 175>
<p>This applet requires version 1.5 or later of Java.</p>
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
</body>
</html>
答案 0 :(得分:3)
我假设当您双击运行jar时出现错误:
java -jar yourjar
然后你应该有一个manifest.mf文件,其中包含以下内容:
Main-Class: MyPackage.MyClass
Main-Class之后有一个CRLF。
然后创建你的jar
jar cfm MyJar.jar manifest.mf MyPackage/*.class
现在你有一个可执行的jar。
如果您在浏览器中遇到主要类清单错误,请发表评论。