2015-02-11 73 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")); 

好吧,我發現我的答案,我希望這會幫助別人了。