2015-02-11 74 views
0

我使用ANT运行我的项目正在运行的任务,从自定义文件夹添加的hibernate.cfg.xml和log4j.properties文件,我有我的hibernate.cfg.xml和我的自定义文件夹中的一个下log4j.properties文件调用/config,当我从蚂蚁运行任务时,由于hibernate.cfg.xml is not found而失败,并显示log4j appenders warnings。无论如何,有可能让蚂蚁在这些文件的自定义文件夹下查找,而不是将它放在src之下。有什么办法,同时从蚂蚁

目标名称 -

<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> 

类路径 -

<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的配置序列 -

hibernateConfig = new Configuration(); 
     hibernateConfig.configure(); 
     StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(hibernateConfig.getProperties()); 
     hibernateSessionFactory = hibernateConfig.buildSessionFactory(ssrb.build()); 
+0

您可以显示您正在尝试运行的示例ANT任务吗? – dg99 2015-02-11 18:15:13

+0

请提供您认为有助于回答此问题的ant文件部分。 – CKing 2015-02-11 18:18:13

+0

@ dg99 - 我已编辑并添加了相关示例。谢谢 – Shek 2015-02-11 18:26:11

回答

0

我研究我的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()); 

这里早先我的代码是 -

hibernateConfig.configure(); 

,我把它改成 -

hibernateConfig.configure (new File(System.getProperty("user.dir")+"/config/hibernate.cfg.xml")); 

好吧,我发现我的答案,我希望这会帮助别人了。