This one time, at band camp, Robert Kent said:
RK>Hi all. I'm new to Castor; I've been reading the documentation on the
RK>website, and also download the shop/shoptest example from the "articles"
RK>page (URL of that example: http://www.drrockit.com/space/castorcodeexample)
RK>
RK>I was having path problems, so I put all of the classes into a package,
RK>com.rjkcomm, to try and alleviate that. My path:
RK>
RK>../ <-- this ("./") is in the classpath
RK>database.xml
RK>shop-mapping.xml
RK>com/
RK> rjkcomm/
RK> Shop.class
RK> ShopTest.class
RK>
RK>The problem:
RK>when I try to run the ShopTest class via "java com.rjkcomm.ShopTest", I get
RK>this exception:
RK>org.exolab.castor.mapping.MappingException: Nested error:
RK>org.exolab.castor.mapping.MappingException: Could not find the class
RK>com.rjkcomm.Shop
RK>
RK>So, how do I get the Shop class to load? It's in the appropriate path for
RK>its package, and the path is in the classpath.
RK>
RK>Pertinent Source Code:
RK>ShopTest.java:
RK> try {
RK> JDO.loadConfiguration( "database.xml" );
RK> } catch (MappingException e) {
RK> System.out.println("Exception: "+e);
RK> }
RK>
RK>database.xml
RK>[ has a mapping element pointing to relative path "shop-mapping.xml" ]
RK>
RK>shop-mapping.xml:
RK><mapping>
RK> <class name="com.rjkcomm.Shop" identity="id">
RK> <!-- ... -->
RK></mapping>
RK>
RK>Prior Messages:
RK>I did search the list archives, and came up with this message:
RK> http://castor.exolab.org/list-archive/msg19773.html
RK>.... which suggests using the "setClassLoader" method to fix problems like
RK>this. Except that JDO.loadConfiguration() is a static method, and
RK>JDO.setClassLoader() is not, and it's my understanding that you're supposed
RK>to do a loadConfiguration() before you allocate an instance of JDO with the
RK>appropriate database name in the constructor. So, I'm not sure how to use
RK>setClassLoader in this situation.
RK>
RK>If this has been addressed elsewhere, please point me to the reference.
RK>
RK>Platform Details:
RK>JDK 1.4.0_02
RK>[ executing from the command line, no servlets or jsp ]
RK>Castor 0.9.4.2
RK>MySQL 3.23.49-8
RK>on debian 3.0
Robert,
+1 for using Debian ;-). I'm a Debian nut, myself. I know that a *LOT*
of people use Debian, but I don't see much evidence on the castor-dev
list of it.
Regarding your classloading issue, this is normally only an issue when
using a container (Serlvet or J2EE). That said, I'll use a portion
of the JDO examples to demonstrate. All of the code below resides
in src/examples/jdo/Test.java with the exception of the call to
setClassloader() that I've added for demonstration purposes:
_jdo = new JDO();
_jdo.setLogWriter( writer );
_jdo.setClassloader( Thread.currentThread().getContextClassloader() );
_jdo.setConfiguration( getClass().getResource( DatabaseFile).toString() );
_jdo.setDatabaseName( "test" );
...
Database db;
...
db = _jdo.getDatabase();
BTW, the setConfiguration() method is not static. Please see
http://www.castor.org/javadoc/org/exolab/castor/jdo/JDO.html.
Bruce
--
perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev