How to access directory listing of archive jar from applet

C

christopher

Greetings,
I can access the contents of the jar files indicated as archives in
the applet tag using the getResource() method. However, I want to be
able to alter the contents of the jar without hard-coding all the file
names. Unfortunately, I cannot find a way to get a directory listing
from the jar file.

In short:
url=getClass().getResource("/"+animationRoot+"/rotate/0.png");
gives a valid URL but:
url=getClass().getResource("/"+animationRoot+"/");
or
url=getClass().getResource("/"+animationRoot);
do not.

Is there a solution to this?
thx
 
A

Arne Vajhøj

I can access the contents of the jar files indicated as archives in
the applet tag using the getResource() method. However, I want to be
able to alter the contents of the jar without hard-coding all the file
names. Unfortunately, I cannot find a way to get a directory listing
from the jar file.

In short:
url=getClass().getResource("/"+animationRoot+"/rotate/0.png");
gives a valid URL but:
url=getClass().getResource("/"+animationRoot+"/");
or
url=getClass().getResource("/"+animationRoot);
do not.

Is there a solution to this?

You can list the content of a jar file with the classes
in java.util.jar package.

Arne
 
A

Arne Vajhøj

Arne said:
You can list the content of a jar file with the classes
in java.util.jar package.

Code snippet:

JarFile jf = new JarFile(jarnam);
Enumeration<JarEntry> e = jf.entries();
while(e.hasMoreElements()) {
JarEntry je = e.nextElement();
String nam = je.getName();
...
}

Arne
 
C

christopher

Code snippet:

             JarFile jf = new JarFile(jarnam);
             Enumeration<JarEntry> e = jf.entries();
             while(e.hasMoreElements()) {
                 JarEntry je = e.nextElement();
                 String nam = je.getName();
                 ...
             }

  Arne

Arne -- in an applet that throws an AccessControlException.
 
A

Arne Vajhøj

in an applet that throws an AccessControlException.

Ooops.

That may be a problem.

I think the easiest would be to have the applet send a HTTP
request to the server where it was retrieved from and call
a dynamic script (ASP, PHP, ASP.NET, JSP etc.) that lists the
content of the jar file and returns it.

Arne
 
C

christopher

Ooops.

That may be a problem.

I think the easiest would be to have the applet send a HTTP
request to the server where it was retrieved from and call
a dynamic script (ASP, PHP, ASP.NET, JSP etc.) that lists the
content of the jar file and returns it.

Arne

Hmmm, I like that idea. I think I will use a text file within the jar
as a simple sort of packing list. It just strikes me as there should
be a way to list the jar contents from within the applet -- or I
should say it frustrates me that there doesn't seem to be one. BTW --
I cannot find a way to enumerate all the resources available to a
Class file or its ClassLoader either. Anyone know why?
 
A

Arne Vajhøj

Hmmm, I like that idea. I think I will use a text file within the jar
as a simple sort of packing list. It just strikes me as there should
be a way to list the jar contents from within the applet -- or I
should say it frustrates me that there doesn't seem to be one. BTW --
I cannot find a way to enumerate all the resources available to a
Class file or its ClassLoader either. Anyone know why?

That is not a problem.

URLClassLoader -> URL's -> listings

The problem is that applets do not have access to
the client PC's disk.

Which is why I suggested moving it serverside.

Arne
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top