The Source for Java Technology Collaboration


Home | Changes | Index | Search | Go

ApplicationDevelopment

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");

Topic ApplicationDevelopment . { Edit | Ref-By | Printable | Diffs r2 < r1 | More }
 XML java.net RSS

Revision r2 - 04 May 2006 - 17:59:14 - Main.paulby
Parents: WebHome > ProjectLookingGlass