-->
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.  [ 7 posts ] 
Author Message
 Post subject: Can't find hibernate.properties in a JARed application
PostPosted: Sat Sep 18, 2004 1:48 am 
Newbie

Joined: Sat Sep 18, 2004 1:36 am
Posts: 12
Hello

I have JARed my application, and when i run the jar, it says cannot find the hibernate.properties and hibernate.cfg.xml files.

Sep 18, 2004 3:24:49 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Sep 18, 2004 3:24:49 PM net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Sep 18, 2004 3:24:49 PM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Sep 18, 2004 3:24:49 PM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
WARNING: /hibernate.cfg.xml not found


Does anyone know what could be happening? These two files are located in the directory where i run the jar file, hence they should be in the classpath.

I did try adding these two files into the actual application jar file, and that worked, however this surely is not the correct method, since they would become uneditable.

Thanks for any help :)

Hibernate version:
2.1.2

Name and version of the database you are using:
mysql 4.0.18


Top
 Profile  
 
 Post subject: Re: Can't find hibernate.properties in a JARed application
PostPosted: Sat Sep 18, 2004 5:06 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
agwibowo wrote:
Does anyone know what could be happening? These two files are located in the directory where i run the jar file, hence they should be in the classpath.


Seems you don't understand how class loading works...
If build an 'executable' jar and execute it with a command like java -jar <jarfile>, then your classpath is limited to this jar and what is specified in its meta-inf. Therefore, if your properties and hbm config files are located *outside* of the jar (in the same directory as you say) - they won't be accessible to your application.

Quote:
I did try adding these two files into the actual application jar file, and that worked, however this surely is not the correct method, since they would become uneditable.


As per what I said above - that's the correct way to do it: include them in your jar file.

If you wan't them outside, then don't use such 'executable' jar and start your application the 'normal' way...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 18, 2004 11:19 pm 
Newbie

Joined: Sat Sep 18, 2004 1:36 am
Posts: 12
Hmm..

Is there any other solution?
What if I want to modify the database location in the future ?
(which is specified in the hibernate.properties)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 19, 2004 4:22 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
You could pass the location of the hibernate properties file in as a parameter.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 1:06 am 
Newbie

Joined: Sat Sep 18, 2004 1:36 am
Posts: 12
Okay..


I'm a total newbieeeee....

Please tell me how do you pass the location of the hibernate.properties
as a parameter.
Is it in the Java code, or in the command line ?


Thanks a lot!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 4:30 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Your main() function in your java code will look something like this...

Code:
public static void main( String[] args )
{
    // extract hibernate.properties location from path
    if ( args.length < 1 )
    {
        System.out.println( "Please specify the hibernate property file" );
        return;
    }

    String location = args[ 0 ];
    File hibernatePropertiesFile = new File( location );
   
    Properties properties = new Properties();
    properties.load( new FileInputStream( hibernatePropertiesFile ) );

    Configuration configuration = new Configuration();
    configuration.addProperties( properties );

    // more code here
}


Then do..

Code:
java -jar MyJar.jar .\hibernate.properties


or wherever your hibernate.properties is.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 11:39 am 
Newbie

Joined: Sat Sep 18, 2004 1:36 am
Posts: 12
Thank you very much!

It works.. you have saved me hours of debugging!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.