• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Loading all icons from jar file

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i am trying to load ALL icons i have in my jar file.
i start with:
.....
Class clazz = Class.forName("com.xxx.IconSelectionDialog");
String me = clazz.getName().replace(".", "/") + ".class";
dirURL = clazz.getClassLoader().getResource(me);
if (dirURL.getProtocol().equals("jar")) {
String jarPath = dirURL.getPath().substring(6, dirURL.getPath().indexOf("!")); //strip out only the JAR file

JarFile jar = new JarFile(jarPath );

Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
while (entries.hasMoreElements()) {
JarEntry nextEntry = entries.nextElement();
String jarEntryName = nextEntry.getName();
.......
.......
}

this works fine while im am debugging from a local jws installation but fails when i start the software with realwebstart from a link.
the error seems to be that the JarFile jar cannot be found even though it has the proper jarPath. can anyone help ?
is there another way to load resources from a jar 8not single named resources, but kind of all *.jpg or similar)

thank you

michael








 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You really dont need to make it this complicated.

Say you got all your image files under images folder.
You can obtain the URL for the folder by getClass().getResource("images");
You can construct a java.io.File object.
On the file object you can call listFiles() which will give you an array of all your image files.
 
michael modenese
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

i thought it is a bit complicated. but:
i got the uri/url of my images directory:

jar:file:/d:/jars_unsigned/software.jar!/images

how exactly do i make a file object to be used via webstart ?

with new file(uri) not possible.

thank you for your reply

michael



 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

michael modenese wrote:hello,
with new file(uri) not possible.



Check out URL#toString() and URI#toASCIIString()
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually you can't make a File object out of a URL unless it's a URL which referred to a file in the first place. And yours isn't.

The standard way to load a set of resources from a jar (or wherever they may be stored) is to provide a list of those resources in the same jar. Then: (1) read the list as a resource (2) for each entry in the list, read that entry as a resource.

Note that the getResourceAsStream() method returns an InputStream which allows you to read the resource.
 
reply
    Bookmark Topic Watch Topic
  • New Topic