wood burning stoves 2.0*
The moose likes Java in General and the fly likes Access to resources via ClassLoader interacts with java-to-exe products Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Access to resources via ClassLoader interacts with java-to-exe products" Watch "Access to resources via ClassLoader interacts with java-to-exe products" New topic
Author

Access to resources via ClassLoader interacts with java-to-exe products

Daniel B. Davis
Greenhorn

Joined: Apr 18, 2003
Posts: 5
A recurring problem is access to resources. If the host operating system is Windows, one type of filepath works; if Linux, a different one works. The solution offered by Java appears to be ClassLoader, in which, as I understand it, the resource is placed somewhere in the classpath, after which the operation classLoader.getResourceAsStream(resource_name); obtains the resource ready to be read as a stream.

In an application, I have successfully used it and the application works under both 'java' and 'javaw' commands. Then I wanted to use a java-to-exe program so that my infrequent users need not download and install the JRE. The first step of the process is to get the thing to work at all under the java-to-exe software, after which I would attack bundling it up.

I chose Winrun4j, and the program starts successfully under it. All normal program functions work, since they do not depend upon anything external, but the following depends upon locating resources using the ClassLoader:
o The HelpSet, upon which the Help system is based
o Log4j Properties, upon which logging is based.
o The About text for the About box.
These do not work.

It may be possible to repackage things for Winrun4j so that these dependencies are added separately and explicitly, and to add command-line arguments to convey the information to the program, but it is inelegant and clumsy, and undoes the good design of ClassLoader. Plus it would need changing when transitioning between Windows, Linux, other operating systems.

A further note: I looked for a way to ask the folks at WinRun4J about this, but although they have a blog, I cannot find how to post to it, or reach them in any other way. So if there is no direct WinRun4J knowledge available, even a way to contact them would be useful.

Any and all ideas or corrections of understanding are gratefully appreciated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Not GUI related. Moving to Java in General.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Daniel B. Davis
Greenhorn

Joined: Apr 18, 2003
Posts: 5
I have found my answer: Classpath had not been set. Sorry to waste everyone's time with this. How may I withdraw the prior post as well as this one?

Thanks much. Having Javaranch is sometimes as good as talking it out to a colleague; sometimes better.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
Daniel B. Davis wrote: . . . How may I withdraw the prior post as well as this one?
You don't. This discussion might be useful for somebody else in future.
 
GeeCON Prague 2014
 
subject: Access to resources via ClassLoader interacts with java-to-exe products