-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to make SessionFactory search the classpath for mappings
PostPosted: Mon May 15, 2006 7:57 pm 
Newbie

Joined: Mon May 15, 2006 7:47 pm
Posts: 1
I am trying to build a Configuration object, so that I can create a SessionFactory that will search my classpath for all mapping files.

If the mapping files are on the file system, it's possible to use the Configuration.addDirectory( File f ) API - so that the entire directory will be searched for mapping files.

And it's possible to specify a specific jar by using the Configuration.addJar( File f ) API.

But I want it to search for any mapping file resource on the classloader - without worrying about which jar the mapping file is in, or if it's being loaded directly by the classloader from an exploded jar structure ( this is what happens when I'm debugging in Eclipse ).
This seems like a basic thing to do, but I can't see how with the current Configuration API.
Can anyone help ?

thanks,

Steph

_________________
steph


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:01 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
If I understood your question correctly, you want to add all jar files in the classpath to the configuration object. Below code can help you.

Code:
String path = System.getProperty( "java.class.path" );
StringTokenizer st = new StringTokenizer( path, ";" );
while ( st.hasMoreToken() ) {
    String jarElement = (String) st.nextElement();
    if ( jarElement.endsWith( ".jar" ) ) {
        // adding only jar files to the Configuration object
        Configuration.addJar( jarElement );
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.