Well, don't forget that you can use Class.getClassLoader().getResource() as well, which does not force you to put e.g. a mapping file in the same directory/package as the class you are using.
Regards Werner Jay Goldman wrote: > Resources are found relative to a particular object - so the jar has to > have the file in the right directory tree. > i.e., XMLUtil.class.getResource(xxx) would look for xxx in the same > 'directory' as the package of XMLUtil.class. > (i.e. if its cedar/hepdata/xml/XMLUtil.class the you must have > cedar/hepdata/xml/hdom-xml-map.xml) > > Typically I put such files in a directory which matches the package some > particular application class. > > -----Original Message----- > From: Andy Buckley [mailto:[EMAIL PROTECTED] > Sent: Wednesday, December 13, 2006 9:08 AM > To: [email protected] > Subject: [castor-user] Loading mapping file from JAR? > > > Hi again, > > I'm trying to package my Castor interface as a JAR package, so that > several "client" applications can use my object models to access our > database. Ideally, there would be no need for each application to have a > local copy of the mapping file -- that would be obtained directly from > the JAR and hence be automatically in sync with the model. > > I'm not sure how to get hold of the mapping file from within a JAR file, > though. Just trying > > public class XMLUtil { > ... > public static Mapping getMapping() { > Mapping mapping = new Mapping(); > try { > mapping.loadMapping("hdom-xml-map.xml"); > ... > } > return mapping; > } > > doesn't work either when building the JAR (I'm using Maven, so have to > use "mapping.loadMapping("target/classes/hdom-xml-map.xml");" --- the > classes directory isn't automatically checked) nor when calling > XMLUtil.getMapping() from a client application. I've had a go at using > XMLUtil.class.getResource("hdom-xml-map.xml") but that just returns > null, even though the file I'm looking for is in that JAR: > > [EMAIL PROTECTED]:~/.../hepdata-migration$ jar tf > /mt/home/buckley/.m2/repository/cedar/hepdata/hepdata-xml/1.0-SNAPSHOT/h > epdata-xml-1.0-20061213.131638-7.jar > META-INF/ > META-INF/MANIFEST.MF > cedar/ > cedar/hepdata/ > cedar/hepdata/xml/ > hdom-xml-map.xml > cedar/hepdata/xml/XMLUtil.class > ... > > Any suggestions? > > Andy > > -- > Andy Buckley: CEDAR @ IPPP, Durham > Work: www.cedar.ac.uk > www.insectnation.org > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email

