Read file from jar when applet loaded by Tomcat

N

Nigel Wade

Hi,

I'm trying to get an applet to load a file from its jar-file. I can do this
by the usual Class.getResource(filename) provided I use an absolute URL for
the codebase in the APPLET tag. However, what I want to do is serve the
HTML from Apache and the jars from Tomcat (the applet read from a servlet
and avoids duplicating the jars in Apache and Tomcat).

If I use codebase="http://www.ion.le.ac.uk:8080/java/lib" in the APPLET tag
then it all works well. However, I'd like to avoid using the hostname in
the URL, i.e. codebase="http://:8080/java/lib". However, this doesn't work.
The jar file is downloaded to the browser and the applet runs, but
getResource(filename) returns null, indicating it couldn't find the
relevent resource/file.

The jarfile in question is called worldMap.jar and contains the class
worldMap.World (i.e. worldMap/World.class). In World.java I use
World.class.getResource("/map_data.i") to load the file /map_data.i from
the jarfile. As I mentioned above if I use an absolute URL for the
classpath it works, but with the hostname omitted from the URL it fails.

Does anyone know what I need to do to get this to work?


The full APPLET tag is:

<applet code="realTimeApplet/StartUp.class"
codebase="http://:8080/java/lib"
archive="realTimeApplet.jar" width="100" height="100">

and the contents of worldMap.jar are:

META-INF/
META-INF/MANIFEST.MF
map_data.i
worldMap/
worldMap/World$LoadFromURL.class
worldMap/World$LoadingMonitor.class
worldMap/World$OutlineGeo.class
worldMap/World$OutlinePath.class
worldMap/World.class
worldMap/WorldMapLoadingException.class
 
T

Thomas Fritsch

Nigel said:
Hi, Hi!

I'm trying to get an applet to load a file from its jar-file. I can do this
by the usual Class.getResource(filename) provided I use an absolute URL for
the codebase in the APPLET tag. However, what I want to do is serve the
HTML from Apache and the jars from Tomcat (the applet read from a servlet
and avoids duplicating the jars in Apache and Tomcat).

If I use codebase="http://www.ion.le.ac.uk:8080/java/lib" in the APPLET tag
then it all works well. However, I'd like to avoid using the hostname in
the URL, i.e. codebase="http://:8080/java/lib". However, this doesn't work.
The jar file is downloaded to the browser and the applet runs, but
getResource(filename) returns null, indicating it couldn't find the
relevent resource/file.

The jarfile in question is called worldMap.jar and contains the class
worldMap.World (i.e. worldMap/World.class). In World.java I use
World.class.getResource("/map_data.i") to load the file /map_data.i from
the jarfile. As I mentioned above if I use an absolute URL for the
classpath it works, but with the hostname omitted from the URL it fails.

Does anyone know what I need to do to get this to work?


The full APPLET tag is:

<applet code="realTimeApplet/StartUp.class"
codebase="http://:8080/java/lib"
archive="realTimeApplet.jar" width="100" height="100">
I think the following applet tag should work:
<applet code="realTimeApplet/StartUp.class"
codebase="/java/lib"
archive="realTimeApplet.jar" width="100" height="100">
But then it is also required that the HTML page containing this applet
tag must be under the same server and *port*, for example at
"http://www.ion.le.ac.uk:8080/bla/blub.html" .
The applet will then get the URL "http://www.ion.le.ac.uk:8080/java/lib"
on getCodeBase().
 
N

Nigel Wade

Thomas said:
I think the following applet tag should work:
<applet code="realTimeApplet/StartUp.class"
codebase="/java/lib"
archive="realTimeApplet.jar" width="100" height="100">
But then it is also required that the HTML page containing this applet
tag must be under the same server and *port*, for example at
"http://www.ion.le.ac.uk:8080/bla/blub.html" .
The applet will then get the URL "http://www.ion.le.ac.uk:8080/java/lib"
on getCodeBase().

Thanks, but unfortunately, the HTML containing the APPLET tag is served by
Apache on port 80...
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top