Hi,
wrote a persistence layer for my project with hibernate tools and now I want to pack it in a jar, so that I could run it somewhere outside from eclipse. For this I use an ant file which we used before, when the persistence layer didn't existed.
When I now want to run the project with the ant file I get an exception (look below). Why doesn't he find the cfg.xml? It is directly in the src/ folder of my project.
And especially: Sometimes he find the file but not the mapping files. Whats wrong there?
It would be great if somebody has an idea.
Carina
Hibernate version: 3.2 beta 8 (HibernateTools)
Name and version of the database you are using: Oracle 10g
Mapping documents:
Used Ant File
Code:
<!--
===================================================================
tutorial build
===================================================================
-->
<project name="CSR" default="compile">
    <!-- environment -->
    <property environment="env"/>
    <property name="project.location" location="."/>
    <property name="project.build.debug" value="on"/>
    <property name="Name" value="CSR"/>
    <property name="name" value="${Name}"/>
    <property name="version" value="0.60"/>
    <!-- project workspace directories -->
    <property name="java.dir" value="src/"/>
    <property name="lib.dir" value="lib"/>
    <property name="lib-ext.dir" value="lib-extern"/>
    <!-- compile properties -->
    <property name="classes.dir" value="class"/>
   
    <!--
    ===================================================================
    Classpath properties
    ===================================================================
    -->
    <!-- libs necessary to build the project -->
    <path id="lib.classpath">
      <fileset dir="." includes="${lib.dir}/*.jar lib-extern/*.jar"/>
    </path>
    <!-- the classpath for the compile -->
    <path id="compile.classpath">
        <pathelement location="${classes.dir}"/>
        <path refid="lib.classpath"/>
    </path>
   <!-- hibernate tasks & location (jar archives)  -->
   <!-- its a suggestion by now
   <path id="hibernatelib">
      <path location="lib-extern/hibernate-tools.jar"/>
      <path location="lib/hibernate3.jar"/>
      <path location="??/freemarker.jar"/>
      <path location="${jdbc.driver.jar}"/>
   </path>
   
   <taskdef
      name="hibernatetool" 
      classname="org.hibernate.tool.ant.HibernateToolTask" 
      classpathref="hibernatelib" />
   -->
    <!--
    ===================================================================
    TARGET : hibernate
    ===================================================================
    -->
    <target name="hibernate">
       <hibernatetool destdir="${project.location}/generated">
         <configuration configurationfile="hibernate.cfg.xml"/>
          <hbm2java/>
      </hibernatetool>
   </target>
   
    <!--
    ===================================================================
    TARGET : clean
    ===================================================================
    -->
    <target name="clean">
        <delete includeEmptyDirs="true" quiet="true">
            <fileset dir="${classes.dir}" includes="**/*.class,**/*.properties,**/*.*"/>
        </delete>
    </target>
   <!--
    ===================================================================
    TARGET : doc
    ===================================================================
    -->
    <target name="javadoc">
      <echo message="bulding Javadoc for ${ant.project.name} to ${basedir}/doc/dev..."/>
       <javadoc access="private" author="true" 
          classpath="lib-extern/250b32_14_os_jpedal.jar:lib/mysql-connector-java-3.1.12-bin.jar:lib/FLEXlmJNI.jar:lib/ij.jar:lib/jargs.jar:lib/ini4j.jar:lib/jai_imageio.jar:lib/jai_codec.jar:lib/jai_core.jar:lib/junit.jar:lib/log4j-1.2.9.jar:lib/JRclient-RE817.jar:lib/mlibwrapper_jai.jar:lib-extern/MarvinBeans.jar:lib/libsvm.jar" 
          destdir="doc/dev" nodeprecated="false" nodeprecatedlist="false" noindex="false" 
          nonavbar="false" notree="false" 
          packagenames="de.fhg.scai.bio.csr.*" 
          source="1.5" sourcepath="src" splitindex="true" use="true" version="true"/>
    </target>   
   
    <!--
    ===================================================================
    TARGET : prepare
    ===================================================================
    -->
    <target name="prepare">
        <mkdir dir="${classes.dir}"/>
    </target>
    <!--
    ===================================================================
    TARGET : compile.java
    ===================================================================
    -->
    <target name="compile" depends="clean,prepare">
        <echo message="==================================================================="/>
        <echo message="Compile configuration:"/>
        <echo message="java.dir       = ${java.dir}"/>
        <echo message="classes.dir    = ${classes.dir}"/>
        <echo message="==================================================================="/>
        <javac srcdir="${java.dir}" destdir="${classes.dir}" debug="${project.build.debug}" classpathref="compile.classpath">
            <include name="**/*.java"/>
         
        </javac>
      <echo message="jarring..."/>
       <!--
      <jar destfile="./bin/csr.${version}.jar" basedir="${classes.dir}"/>
      -->
      <jar destfile="./bin/csr.${version}.jar">
         <fileset dir="${classes.dir}"/>
         <fileset dir="${java.dir}" includes="hibernate.cfg.xml"/>
      </jar>
    </target>
   
    
</project>
Full stack trace of any exception that occurs:Code:
2007-05-24 12:43:49,754 INFO  [de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:114)]  >> Starting workflow: Connect with database
2007-05-24 12:43:49,754 INFO  [de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:64)]  >> (13/13) - Communicating with database ...
2007-05-24 12:43:50,024 INFO  [org.hibernate.cfg.Environment.<clinit>(Environment.java:509)] Hibernate 3.2.3
2007-05-24 12:43:50,040 INFO  [org.hibernate.cfg.Environment.<clinit>(Environment.java:542)] hibernate.properties not found
2007-05-24 12:43:50,043 INFO  [org.hibernate.cfg.Environment.buildBytecodeProvider(Environment.java:676)] Bytecode provider name : cglib
2007-05-24 12:43:50,055 INFO  [org.hibernate.cfg.Environment.<clinit>(Environment.java:593)] using JDK 1.4 java.sql.Timestamp handling
2007-05-24 12:43:50,236 INFO  [org.hibernate.cfg.Configuration.configure(Configuration.java:1426)] configuring from resource: /hibernate.cfg.xml
2007-05-24 12:43:50,241 INFO  [org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1403)] Configuration resource: /hibernate.cfg.xml
Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found
Exception in thread "Thread-1" java.lang.ExceptionInInitializerError
   at de.fhg.scai.bio.csr.io.database.communication.HibernateUtil.<clinit>(HibernateUtil.java:17)
   at de.fhg.scai.bio.csr.io.database.communication.StoreData.startSession(StoreData.java:314)
   at de.fhg.scai.bio.csr.io.database.communication.StoreData.saveWorkflow(StoreData.java:124)
   at de.fhg.scai.bio.csr.io.database.communication.StoreData.run(StoreData.java:105)
   at de.fhg.scai.bio.csr.workflows.algorithms.DatabaseCommunication.run(DatabaseCommunication.java:73)
   at de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:96)
   at de.fhg.scai.bio.csr.workflows.interfaces.WorkflowModule.execute(WorkflowModule.java:156)
   at de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:115)
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
   at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
   at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
   at de.fhg.scai.bio.csr.io.database.communication.HibernateUtil.<clinit>(HibernateUtil.java:13)
   ... 7 more
Code:
2007-05-24 12:43:21,913 INFO  [de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:64)]  >> (13/13) - Communicating with database ...
2007-05-24 12:43:21,977 INFO  [org.hibernate.cfg.Environment.<clinit>(Environment.java:509)] Hibernate 3.2.3
2007-05-24 12:43:21,981 INFO  [org.hibernate.cfg.Environment.<clinit>(Environment.java:542)] hibernate.properties not found
2007-05-24 12:43:21,984 INFO  [org.hibernate.cfg.Environment.buildBytecodeProvider(Environment.java:676)] Bytecode provider name : cglib
2007-05-24 12:43:21,989 INFO  [org.hibernate.cfg.Environment.<clinit>(Environment.java:593)] using JDK 1.4 java.sql.Timestamp handling
2007-05-24 12:43:22,061 INFO  [org.hibernate.cfg.Configuration.configure(Configuration.java:1426)] configuring from resource: /hibernate.cfg.xml
2007-05-24 12:43:22,062 INFO  [org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1403)] Configuration resource: /hibernate.cfg.xml
2007-05-24 12:43:22,335 INFO  [org.hibernate.cfg.Configuration.addResource(Configuration.java:553)] Reading mappings from resource : de/fhg/scai/bio/csr/io/database/hibernate/DatabaseRun.hbm.xml
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: de/fhg/scai/bio/csr/io/database/hibernate/DatabaseRun.hbm.xml not found
Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
        at de.fhg.scai.bio.csr.io.database.communication.HibernateUtil.<clinit>(HibernateUtil.java:17)
        at de.fhg.scai.bio.csr.io.database.communication.StoreData.startSession(StoreData.java:314)
        at de.fhg.scai.bio.csr.io.database.communication.StoreData.saveWorkflow(StoreData.java:124)
        at de.fhg.scai.bio.csr.io.database.communication.StoreData.run(StoreData.java:105)
        at de.fhg.scai.bio.csr.workflows.algorithms.DatabaseCommunication.run(DatabaseCommunication.java:73)
        at de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:96)
        at de.fhg.scai.bio.csr.workflows.interfaces.WorkflowModule.execute(WorkflowModule.java:156)
        at de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:115)
Caused by: org.hibernate.MappingNotFoundException: resource: de/fhg/scai/bio/csr/io/database/hibernate/DatabaseRun.hbm.xml not found
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
        at de.fhg.scai.bio.csr.io.database.communication.HibernateUtil.<clinit>(HibernateUtil.java:13)
        ... 7 more