简体   繁体   English

有没有办法在从ant运行任务时从自定义文件夹添加hibernate.cfg.xml和log4j.properties文件

[英]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.xmllog4j.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.

相关问题 如何从外部项目文件夹访问hibernate.cfg.xml,config.properties和log4j.properties - How to Access hibernate.cfg.xml, config.properties, and log4j.properties from outside project folder hibernate.cfg.xml-从属性文件设置参数 - hibernate.cfg.xml - Set parameters from a properties file 从JAR文件运行应用程序时,找不到hibernate.cfg.xml错误 - hibernate.cfg.xml not found error while running the application from JAR file 属性hibernate.cfg.xml - properties hibernate.cfg.xml 仅具有hibernate.properties文件的Hibernate配置。 没有任何hibernate.cfg.xml - Hibernate Configuration with only hibernate.properties file. Without any hibernate.cfg.xml 如何在命令提示符下运行jar文件时在log4j.properties文件中指定日志文件位置 - How to specify log file location in log4j.properties file While running jar file from command prompt Log4j无法从资源文件夹中提取log4j.properties文件 - Log4j not picking up log4j.properties file from resources folder hibernate.cfg.xml 没有找到 hibernate.properties 文件 - hibernate.cfg.xml does not find hibernate.properties file 使用hibernate.cfg.xml时更改hibernate.properties文件的位置 - Change location of hibernate.properties file while using hibernate.cfg.xml 从 aplication.properties 文件获取 log4j.properties 文件的路径到 web.xml - Getting path of log4j.properties file from aplication.properties file into web.xml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM