0

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>
zengr
  • 38,346
  • 37
  • 130
  • 192
Mike
  • 1
  • 1
  • 2
  • Note jar files are zip files, so you can use a standard unzip utility (or `jar xf`) to have a look at exactly what the manifest says. / Running as an application of the command line also requires a `main` method, with the applet business being ignore (unless you use `appletviewer). – Tom Hawtin - tackline Dec 12 '10 at 21:09

1 Answers1

3

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.

Usman Saleem
  • 1,665
  • 9
  • 18