Shiva-
If the mapping files are in the classpath, the quickest way I've found
to get at them is the following:
URL mappingURL = (mappedClass).class.getResource( pathToFile );
mapping.loadMapping( mappingURL );
pathToFile here is relative to the classpath, so if classes is at the
root of the classpath, simply "/mapping.xml" should do it. If, for
instance, the mapping files were in a mapping package (I've done this
in the past), the path is "/mapping/mapping.xml". The basic idea is
to call getResource on the ClassLoader object that is responsible for
the mapped classes.
If you just pass loadMapping a string (as in your example) I think
Castor first looks for a full path, then a path relative to the
current working directory (which I find a confusing concept in a lot
of web-apps), and then I think there is a third fallback, but I'm not
sure what it is. I had problems in the past (several versions ago)
with relative paths, which is why I switched to the URL approach.
I don't think that directly answers your question, but it is an
approach I've found useful. If I get a chance I'll look at the code
more carefully and let you know exactly what loadMapping( String )
does.
Stephen
On 3/1/06, Shiva P. Kodityala <[EMAIL PROTECTED]> wrote:
> I kept Castor-XML mapping files in classes directory (WEB-INF/classes).
> These mapping files are to convert XML data to Java objects. How does Castor
> (below statement) recognise these files?
>
> mapping.loadMapping("mapping.xml");
>
> Currently, I am giving full path of these files. I kept those files in
> classes directory thinking that they would be read because they are in
> classpath. Anybody has any idea, how to do this with relative path instead of
> absolute path?
>
>
> Thanks
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>