无法加载主类清单属性

发布于 2024-10-07 13:43:41 字数 1824 浏览 3 评论 0原文

我创建了一个在网络浏览器上运行的简单小程序。我通过在命令提示符中运行“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>

I created a simple applet to run on a web browser. i create Jar file by running "C:\Program Files\Java\jdk1.6.0_21\bin\jar" cfv Project7Applet.jar *.class in a command prompt and then when i try to run the jar file i get the "failed to load main-class manifest attribute error" However i don't understand why this happens because in the command prompt when i create the jar file it says

added manifest
adding: Project7Applet.class.....
adding: Project7Panel.class...

here's my .html file

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

罗罗贝儿 2024-10-14 13:43:41

我假设当您双击运行 jar 时出现错误:

java -jar yourjar

然后您应该有一个包含以下内容的 manifest.mf 文件:

Main-Class: MyPackage.MyClass

Main-Class 之后有一个 CRLF。

然后创建你的 jar

jar cfm MyJar.jar manifest.mf MyPackage/*.class

现在你有一个可执行的 jar 了。

如果您在浏览器中遇到主类清单错误,请发表评论。

I am assuming that your error is coming when you are double clicking of running your jar as:

java -jar yourjar

Then you should have a manifest.mf file with following contents:

Main-Class: MyPackage.MyClass

There is a CRLF after Main-Class.

Then create your jar as

jar cfm MyJar.jar manifest.mf MyPackage/*.class

Now you have an executable jar.

Please comment if you are facing the main-class manifest error within your browser.

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