My question is expressed in terms of these
two Images.
In the first one, configuration.configure() method of hibernate loads the
file from src folder as indicated by red arrows
While in this second image,
it is shown that PropertyConfigurator.configure() method of Log4j loads the file from
root folder of Project as indicated by the red arrows again
In both projects, this and only this setup works and no alternate setup works.
Thanks for help.
Eclipse isn't doing anything, it's all the JVM. the results would be the same if you used the command line or another IDE.
The different programs load configuration diferently in your 2 examples.
src
. sourcode of Hibernate's Configuration#configure(String)
FileInputStream
. Since you give a relative path, it looks for a file relative the root of your project load hibernate.cfg.xml
configuration.configure(hibernate.cfg.xml)
means your hibernate configuration file “hibernate.cfg.xml” is at the root of your project classpath.Even if you don't pass the configuration file name in the configure() method, it will work, but in that case name should be hibernate.cfg.xml.
If you want to place this configuration file into a different directory then you need do like below
new Configuration().configure("/com/config/hibernate.cfg.xml")
load log4j.properties
Loading log4j.properties also works in the similar way.
If you want to put your log4j.properties in to com-->config source folder you can do like below
PropertyConfigurator.configure("classpath:com/config/log4j.properties");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.