Sign in to follow this  
caseyd

[java] Help with jar files [Solved]

Recommended Posts

Hi, I just made an applet based Asteroids clone, and I am trying to create a jar file. Whenever I click on the jar file (in windows) it gives me a fatal exception occured. I am using this line to create my jar file: jar cvfm Asteroids.jar manifest.txt asteroids/*.class where asteroids is my package, and the directory that contains all the classes. My main class is called Asteroids.class. In the manifest file I have: Main-Class: asteroids.Asteroids including the new line at the end. I'm using eclipse as my ide and the applet runs fine within that. When I try and run the applet within Firefox, the status bar at the bottom says "Loading java applet failed". Checking the java console, I see this:
load: class Asteroids.class not found.
java.lang.ClassNotFoundException: Asteroids.class
	at sun.applet.AppletClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadCode(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Projects\java\Asteroids\Asteroids\class.class (The system cannot find the file 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.applet.AppletClassLoader.getBytes(Unknown Source)
	at sun.applet.AppletClassLoader.access$100(Unknown Source)
	at sun.applet.AppletClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 10 more


In my html file I have this
<html>
<head><title></title></head>

<body>
	<applet code="Asteroids.class" archive="Asteroids.jar" width="640" height="480"></applet>
</body>
</html>


I've looked around at Sun's website and tried a few different things, but I can't seem to get this to load correctly. I'm sure it's something little I'm forgetting but I'm kind of tired.. All help is greatly appreciated. Thanks [Edited by - caseyd on June 13, 2006 10:04:10 AM]

Share this post


Link to post
Share on other sites
The explorer thing is likely a program you've installed registered to say it can handle .jar files as archives (which is all they really are, .zip files with a different extension) - but it cannot.

As far as the class not found thing, it's because you've not told it in the command line or the jar's menifest which class contains the main() and where.

That's kind of Java 101 stuff, any good Java book should be able to point you in the right direction.

I mean look at the error:
C:\Projects\java\Asteroids\Asteroids\class.class

I'm guessing you don't have a class called class?

Perhaps this link might help:
http://java.sun.com/developer/codesamples/compression.html

Share this post


Link to post
Share on other sites
Thanks for your response. I did indicate in my manifest file the name of the main class. Asteroids.class. This is also an applet so there is no "main". As I also said in the post, I tried following the examples from Sun's website and a book. I have a feeling that there is something causing a conflict here, that I can't figure out.

Share this post


Link to post
Share on other sites
You need to put the full package path to your class:


<html>
<head><title></title></head>

<body>
<applet code="Asteroids.Asteroids.class" archive="Asteroids.jar" width="640" height="480"></applet>
</body>
</html>



ps. As a convention, Java packages should not contain captial letters. If you use this convention, it will be easier for someone to help you.

Share this post


Link to post
Share on other sites
Thanks CaptainJester. That fixed the problem loading the applet in the web browser, but I still can't run the jar file from explorer. As paulecoyote said, it's probably not being loaded right by the program. But, that's not as important to me. I'll have to mess around with it later.

Oh, wait a minute...You can't run applets that way. They have to be run using appletviewer.exe.

Again, thanks to the both of you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this