[英]Is there any way to add hibernate.cfg.xml and log4j.properties file from custom folder while running tasks from ant
I am using ANT to run my project, I have my hibernate.cfg.xml
and log4j.properties
file under one of my custom folder called /config
, When I run tasks from ant it fails due to hibernate.cfg.xml is not found
and shows log4j appenders warnings
. 我正在使用ANT运行我的项目,我的hibernate.cfg.xml
和log4j.properties
文件位于我的自定义文件夹之一/config
,当我从ant运行任务时,由于hibernate.cfg.xml is not found
失败并显示log4j appenders warnings
。 By any means is it possible to have ant look under your custom folder for these files rather then placing it under src
. 无论如何,都可以在您的自定义文件夹下查找这些文件的ant,而不是将其放在src
下。
Target Name - 目标名称 -
<target name="controlGRID" depends="compile">
<echo>
Please wait .... GRID is starting up...
</echo>
<java classname="foo.bar.framework.selenium.SetupGrid" classpath="${test.dest}" classpathref="test.c">
<arg value="${arg}"/>
</java>
<echo>
GRID Start up complete !
</echo>
</target>
Classpath - 类路径 -
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
<!--<pathelement path="${foobar.config}"/>-->
<pathelement location="${foobar.config}"/>
<fileset dir="${foobar.config}">
<include name="hibernate.cfg.xml"/>
<include name="log4j.properties"/>
</fileset>
</path>
Hibernate configuration sequence - Hibernate配置顺序 -
hibernateConfig = new Configuration();
hibernateConfig.configure ();
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(hibernateConfig.getProperties());
hibernateSessionFactory = hibernateConfig.buildSessionFactory(ssrb.build());
I have researched my hibernate classes and found a solution: 我研究了我的hibernate类并找到了解决方案:
hibernateConfig = new Configuration();
hibernateConfig.configure (new File(System.getProperty("user.dir")+"/config/hibernate.cfg.xml"));
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(hibernateConfig.getProperties());
hibernateSessionFactory = hibernateConfig.buildSessionFactory(ssrb.build());
Here earlier my code was - 早些时候,我的代码是 -
hibernateConfig.configure();
and I changed it to - 我改成了 -
hibernateConfig.configure (new File(System.getProperty("user.dir")+"/config/hibernate.cfg.xml"));
Well I found my answer, I hope it'll help somebody else too. 好吧,我找到了答案,希望它也能对其他人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.