cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Cayenne 3.1M2 cannot locate Configuration file "..conf/UntitledDomain.xml" is not found.
Date Thu, 18 Aug 2011 11:03:23 GMT
Hi there,

There are a few things at play here (and I think there's also a Cayenne bug in 3.1 that we
need to fix )... So when you do this:

  ServerRuntime econfigContext = new ServerRuntime("conf/cayenne-UntitledDomain.xml") 

The location String ("conf/cayenne-UntitledDomain.xml" in your case) is internally resolved
to a "resource" using org.apache.cayenne.resource.ResourceLocator service. Its default implementation
is ClassLoaderResourceLocator. So the location is interpreted as a Java resource accessible
somewhere on CLASSPATH. 

If you decide to move your XML file out of CLASSPATH location and to somewhere outside the
application, you will need to change this strategy from CLASSPATH resource lookup to filesystem
lookup. org.apache.cayenne.resource.FilesystemResourceLocator supports finding resources on
the filesystem, as the name suggests.

So you will need to create a custom module that configure the default ResourceLocator to be
FilesystemResourceLocator. E.g.:

 Module myModule = new Module() {
    void configure(Binder binder) {
         binder.bind(ResourceLocator.class).toInstance(new FilesystemResourceLocator(new File("c:\"));

 ServerRuntime econfigContext = new ServerRuntime("conf/cayenne-UntitledDomain.xml", myModule);

Now Cayenne will look for all locations relative to "c:\". But make sure all you .map.xml
files are also in the same location as the main XML, as they will be resolved via relative

Now unfortunately there's a glitch with rebinding ResourceLocator in this way (or at least
I think there is, I haven't tried a test to reproduce it) - in addition to loading user XML
files, the default ResourceLocator is also used to load DbAdapter types.xml file (an internal
Cayenne thing that users rarely have to care about). I will log this bug in Jira to investigate
further. As a temporary workaround, you may grab types.xml from Cayenne sources and put it
in C:\ (or a subfolder of C:\ that you designate as a FilesystemResourceLocator "root").

Hope this helps.


On Aug 18, 2011, at 12:13 PM, Eldred Mullany wrote:

> Hi Everyone
> I have a command line app that initiates ServerRuntime econfigContext =
> new ServerRuntime("conf/cayenne-UntitledDomain.xml") from my main apps
> constructor. The cayenne-UntitledDomain.xml is referenced from my
> main/src/resources/conf directory. 
> The problem is if I move this file out of the location to
> "c:/configs/cayenne-UntitledDomain.xml" I get a
> org.apache.cayenne.configuration.server.DataDomainLoadException . 
> Because this file loaded at runtime it cayenne cannot find it anywhere
> else but from main/src/resources/ path. I need to make this xml
> accessible so that users can change the jdbc connection settings ? 
> Why does c:/configs/cayenne-UntitledDomain.xml throw an exception ? 
> Many thanks 

View raw message