Jar application, what is the classpath?

jonasdb

New Member
Messages
19
Reaction score
0
Points
0
Hello guys,

I've made a little thingy in java and jarred it, now to display it on my webpage to what directory should i upload it and what would be the classpath (codebase/archive) ?

this is what i have:

Code:
<html> 
<head> 
<title>My Applet Page</html> 
</head> 
 
<body> 
<applet code="Chat.class" archive="http://AAA.x10hosting.com/app.jar" width="600px" height="450px"> 
Java is not installed on your machine or your browser does not allowed Java Applet to run<br /><br />Get the latest Java technology at <a href="http://www.java.com/">http://www.java.com/</a> 
</applet> 
</body> 
</html>

the name is app.jar and the content is only 1 file, Chat.class

its simple class which extends Applet
and draws a circle
altough when i load the webpage it doesn't show anything, nor a java sign or w/e

Any ideas??

Thanks in advance!
 
Last edited:

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
can you attach the jar file here. So we can check it too.
 

jonasdb

New Member
Messages
19
Reaction score
0
Points
0
Ok sure,but i cant attach it lol :p
ill uploaded: http://basketsite.x10hosting.com/app.jar

content of Chat.java

package chat;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class Chat extends Applet
{

/**
*
*/
private static final long serialVersionUID = 1L;

public static void main(String[] args)
{
Chat c =new Chat();
}



public void paint( Graphics g )
{
super.paint( g );
g.setColor(Color.RED);
g.fillRect(0, 0, 500, 500);
g.drawRect( 900, 40, 30, 900 );
g.fillRect( 200, 70, 80, 80 );
g.fillOval( 100, 50, 40, 100 );
g.drawOval( 100, 200, 100, 40 );
int X = 250, Y = 225;
int r = 25;
g.drawOval( X - r, Y - r, r * 2, r * 2 );
}

}

-> http://basketsite.x10hosting.com/app.jar
 
Last edited:

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
One thing I noticed:
Code:
code="Chat.class"
This is wrong: it should be "chat.Chat" - The 2 errors are:
a) No need to mention .class in the name
b) The package has to be mentioned.

Also the jar file has the wrong structure, Chat.class should be in a folder called chat, since it is part of the package chat.
 
Last edited:

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
I tried to run in firfox.

In java console it is showing an exception

java.lang.UnsupportedClassVersionError: Bad version number in .class file

Check out. I will try to recompile and try to run it again.


EDIT:

There is one more thing in your jar

It contains chat.class nothing else;

But in the code it is given as package chat.

That means the class file must be inside chat folder and when you are trying to make jar
give application entry point..

It will work...
 
Last edited:

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
java.lang.UnsupportedClassVersionError: Bad version number in .class file

Check out. I will try to recompile and try to run it again.
That probably means you are using a jre older than the jdk the file was compiled with. E.g. if you are using java 4 (1.4) and you try running something compiled with java 6 (1.6) then you will get a version error, since the older jre doesn't understand the newer code (unless you set the compiler to compile with 1.4 compliance level, in which case it will generate code of older spec, which will work with an older jre).
 

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
That probably means you are using a jre older than the jdk the file was compiled with. E.g. if you are using java 4 (1.4) and you try running something compiled with java 6 (1.6) then you will get a version error, since the older jre doesn't understand the newer code (unless you set the compiler to compile with 1.4 compliance level, in which case it will generate code of older spec, which will work with an older jre).

Actually i have 2 versions with me now. 1.5 and 1.6 after seeing the manifest file i changed jre and now the exception is eliminated.... :)
 

jonasdb

New Member
Messages
19
Reaction score
0
Points
0
Ok guys, i tried doing what you said, but unfortunately i still doesn't work.

This is what i did: create a new folder with the name 'chat', but the compiled class of Chat.java in it, used JARMaker to jar the folder, now i tried setting the path right with and without the .class, i tried change the archive also but unfortunately i wasn't be able to fix it.

If anyone could try it with my files, here they are:
http://basketsite.x10hosting.com/app5.html
http://basketsite.x10hosting.com/app5.jar

I also found there was an option about the manifest file, i put the classpath in it (just unzip the jar and you'll see it), it might be incorrect, but i tried alot but still it doesn't work :(

Any help is appreciated!
Thanks for all the help already!
 

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
Ok guys, i tried doing what you said, but unfortunately i still doesn't work.

This is what i did: create a new folder with the name 'chat', but the compiled class of Chat.java in it, used JARMaker to jar the folder, now i tried setting the path right with and without the .class, i tried change the archive also but unfortunately i wasn't be able to fix it.

If anyone could try it with my files, here they are:
http://basketsite.x10hosting.com/app5.html
http://basketsite.x10hosting.com/app5.jar

I also found there was an option about the manifest file, i put the classpath in it (just unzip the jar and you'll see it), it might be incorrect, but i tried alot but still it doesn't work :(

Any help is appreciated!
Thanks for all the help already!
That jar file still is incorrect: Chat.class is in the top folder, and should be in the folder chat. I made a test page to which I uploaded the applet:
http://www.ahunt.org/java.html
Code:
<html><body>
<applet code="chat.Chat" archive="http://www.ahunt.org/chat2.jar" width="600px" height="450px" /> 
</body></html>
I also compiled and "jarred" the java file, here:
http://www.ahunt.org/chat2.jar
This file has the structure:
>META-INF
-----------------| MANIFEST.MF
>chat
-----------------| Chat.class

To make life easier, try remove the package declaration from Chat.java, and then change the starting point in the html file to Chat
 

jonasdb

New Member
Messages
19
Reaction score
0
Points
0
It does work now, altough i found another problem which caused it and that was because i had an autogenerated html page too, and at the top there was something of <documenttype> and when i removed it it worked fine lol :p, but also the package was the problem

So thank you very much for all you helps!
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
It does work now, altough i found another problem which caused it and that was because i had an autogenerated html page too, and at the top there was something of <documenttype>

The page should have a doctype.
 
Top