-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Packing project in jar: Hibernate.cfg.xml or other not found
PostPosted: Thu May 24, 2007 6:52 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
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


Last edited by N-te Jr. on Thu May 24, 2007 7:08 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:59 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

You didn't send packaging part of the ant file


Amila


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 7:09 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
amila733 wrote:
Hi

You didn't send packaging part of the ant file


Amila


Added the whole ant file.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 8:04 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Make sure that all .hbm.xml files are with .class file and hibernate.cfg.xml in root level


Amila


(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 10:58 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
Solved it by adding this: <fileset dir="${java.dir}" includes="**/*.xml"/> to the jarring part. Was really to easy, thats why I didn't found out fro a lot of days... :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.