Home | Changes | Index | Search | Go
Tips and Tricks for Application Developers
Using XMLDecoder in applications
If you use XMLDecoder to load data files into your app be sure to pass the correct ClassLoader? to XMLDecoders constructor. Using the default system ClassLoader? will not work. Follow this sort of pattern
ExceptionListener exceptionListener = new ExceptionListener() {
public void exceptionThrown(Exception e) {
logger.warning("Problem Reading Config File : "+e.getMessage());
}
};
InputStream is = getClass().getClassLoader().getResourceAsStream("org/jdesktop/lg3d/apps/myapp/myconfig.xml");
XMLDecoder decoder = new XMLDecoder(is, null, exceptionListener, getClass().getClassLoader());
Resources
Load resources from your applications jar using the following pattern
getClass().getClassLoader().getResource("org/jdesktop/lg3d/apps/myapp/myconfig.xml");
|