JAR-ing a package?

S

srdjan

I have a package named "my_package" and a applet class in it called
"MyNumber". I'm calling it from my .html file like this:

<applet
codebase ="."
code ="my_package.MyNumber.class"
archive ="my_package.jar"
....
</applet>

When I try to run the .html file I get:

- java.lang.ClassNotFoundException: my_package.MyNumber.class
....
and

- Caused by: java.io.FileNotFoundException:
C:\my_package\my_package\MyNumber\class.class (The system cannot find the
path specified)
....

The .jar file and the .html file are in the same directory. The .jar file
was made "above" the "\my_package" directory like this:
jar cf my_package.jar my_package

How should I make the .jar file and where should I put it relative to the
..html file? Any help? Please.
srdjan
 
V

VisionSet

srdjan said:
I have a package named "my_package" and a applet class in it called
"MyNumber". I'm calling it from my .html file like this:

<applet
codebase ="."
code ="my_package.MyNumber.class"
archive ="my_package.jar"
...
</applet>

When I try to run the .html file I get:

- java.lang.ClassNotFoundException: my_package.MyNumber.class
....

If you have a look on Roedy's Java FAQ at

http://mindprod.com/jgloss/applet.html#APPLET

There is quite some detail!
 
A

Andrew Thompson

srdjan said:
I have a package named "my_package" and a applet class in it called
"MyNumber". I'm calling it from my .html file like this:

<applet
codebase ="."
code ="my_package.MyNumber.class"
archive ="my_package.jar"
...
</applet>

When I try to run the .html file I get:

- java.lang.ClassNotFoundException: my_package.MyNumber.class
...
and

- Caused by: java.io.FileNotFoundException:
C:\my_package\my_package\MyNumber\class.class (The system cannot find the
path specified)

Something seems wrong here, it looks as
though the html ingnored the 'archive' parameter
and is expecting the file to be on the local
filesystem, and it should not be looking
for 'class.class'
...

The .jar file and the .html file are in the same directory. The .jar file
was made "above" the "\my_package" directory like this:
jar cf my_package.jar my_package

....hmmm. Do this, rename your .jar to .zip
(you using Windows?) and open it in WinZip
or similar - is the structure as you expect it?

[ I suspect you have accidentally picked up
a 'my_package' too many in there somewhere,
but I'm not sure.. ]
How should I make the .jar file and where should I put it relative to the
.html file? Any help? Please.

Can you put the files on the net?
An URL is the best way to debug applets,
- put links to the source, jar, .bat files etc.
 
S

srdjan

The package should have been made like this:

jar -cf my_package/my_package.jar my_package/*.class

Thanks for your help.

srdjan
 
C

Chris Smith

You should not specify both "codebase" and "archive" attributes to
applet at the same time. They are conflicting, and it looks like the
system chose to use codebase instead of archive, which causes some of
your problems.

The remaining problem is that you've confused the browser with the
".class" at the end of the "code" attribute. Most browsers are smart
enough to accept *either* of a path to the class file *or* a class name
as the value of that attribute. You've given neither one, though;
instead you start as if you're giving a class name, and then end up as
if you're giving a file path. The browser ends up deciding that you
specified a class name, not a file path, and it fails trying to load the
corresponding class file. Pick one or the other form; I prefer class
names myself.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew Thompson

Chris Smith said:
You should not specify both "codebase" and "archive" attributes to
applet at the same time.

News to me Chris, ..did you mean like this?
...
archive="./my_package.jar"
....
 
C

Chris Smith

Andrew said:
News to me Chris, ..did you mean like this?
..
archive="./my_package.jar"
...

No, I mean that the tag should be one of:

<applet
codebase ="."
code ="my_package.MyNumber"
</applet>

or:

<applet
archive ="my_package.jar"
code ="my_package.MyNumber">
</applet>

, depending on whether the code is to found in a JAR file or in the
current directory. (I also fixed the other ".class" issue in the
examples there.)

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

srdjan

Saw this for the first time!

srdjan


Chris Smith said:
No, I mean that the tag should be one of:

<applet
codebase ="."
code ="my_package.MyNumber"
</applet>

or:

<applet
archive ="my_package.jar"
code ="my_package.MyNumber">
</applet>

, depending on whether the code is to found in a JAR file or in the
current directory. (I also fixed the other ".class" issue in the
examples there.)

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top