-->
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.  [ 3 posts ] 
Author Message
 Post subject: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
PostPosted: Fri Mar 18, 2011 12:05 pm 
Newbie

Joined: Fri Mar 18, 2011 11:52 am
Posts: 2
I'm having trouble getting Hibernate up and running using Ant and Ivy. I expect the solution is straightforward, but I haven't been able to find a workable solution on Google or the forums. Any help would be much appreciated.

I'm trying to executed the following task

Code:
<hibernatetool destdir="${build.dir}">
  <classpath refid="run.classpath"/>
  <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
  <hbm2ddl drop="true" create="true" export="true"
                outputfilename="helloworld-ddl.sql" format="true"/>
</hibernatetool>


But I this generates the following error:

Code:
BUILD FAILED
XX/hibernate-test/build.xml:76: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory


The obvious problem here is that slf4j-api isn't present and/or I'm missing an implementation. I've checked this (printing out my classpath from Ant) and verfyied that my path includes the following:
Code:
lib/antlr-2.7.6.jar
lib/bsh-2.0b4.jar
lib/c3p0-0.9.1.jar
lib/commons-collections-3.1.jar
lib/dom4j-1.6.1.jar
lib/freemarker-2.3.8.jar
lib/hibernate-c3p0-3.6.2.Final.jar
lib/hibernate-commons-annotations-3.2.0.Final.jar
lib/hibernate-core-3.6.2.Final.jar
lib/hibernate-jpa-2.0-api-1.0.0.Final.jar
lib/hibernate-tools-3.2.4.GA.jar
lib/hsqldb-1.8.0.7.jar
lib/jta-1.1.jar
lib/jtidy-r8-20060801.jar
lib/log4j-1.2.16.jar
lib/slf4j-api-1.6.1.jar
lib/slf4j-log4j12-1.6.1.jar
lib/xml-apis-1.0.b2.jar
build/classes


Moreover, running a conditional check, I've verifyied through Ant that the class org.slf4j.LoggerFactory is available on 'run.classpath'.

Here's the build file:
Code:
<?xml version='1.0' encoding='utf-8'?>
<project name="hibernate-test" default="package" basedir=".">

  <!-- Import the basic default project -->
  <import file="${basedir}/../build-tools/basic.xml"/>

  <!-- ==================================================================== ==>
  <!== Demand loading support for add-on tasks which may not be pressent.
  <!== ==================================================================== -->

  <property name="proj.name" value="hibernate-test"/>
  <property name="proj.version" value="1.0"/>

  <!-- ==================================================================== ==>
  <!== Path definitions
  <!== ==================================================================== -->

  <!-- useful shortcuts -->
  <patternset id="meta.files">
      <include name="**/*.xml"/>
      <include name="**/*.properties"/>
  </patternset>

  <path id="run.classpath">
    <path refid="lib.classpath" />
    <pathelement location="${classfile.dir}" />
  </path>

  <!-- ==================================================================== ==>
  <!== Hibernate related tasks
  <!== ==================================================================== -->

  <!-- Path to Hibernate tools. For now, this is just the main lib path, but
       setting this up separately lets us change this if needed -->
  <path id="hibernate-tools.path">
    <path refid="lib.classpath"/>
  </path>

  <condition property="hibernate.activated.check" value="yes">
    <typefound name="hibernatetool"/>
  </condition>

  <!-- Activates the Ant tasks for Hibernate, making them available for use in this
       instance of Ant, if they aren't already. It will abort the build if activation
       fails. -->
  <target name="activate-hibernate" depends="resolve"
          unless="hibernate.activated.check">
    <echo message="Activating Ant tasks for Hibernate ${hibernate.version}"/>

    <taskdef name="hibernatetool"
             classname="org.hibernate.tool.ant.HibernateToolTask"
             classpathref="hibernate-tools.path"/>

    <condition property="hibernate.activated.check" value="yes">
        <typefound name="hibernatetool"/>
    </condition>

    <fail message="Activating Hibernate $(hibernate.version} failed...aborting build"
          unless="hibernate.activated.check"/>
  </target>

  <!-- Copy the Hibernate configuration files from the soruce code directiory
       into the build directory. -->
  <target name="copy-metafiles">
      <copy todir="${classfile.dir}">
          <fileset dir="${src.dir}">
              <patternset refid="meta.files"/>
          </fileset>
      </copy>
  </target>

  <!-- Initialize the database -->
  <target name="init-database" depends="compile, copy-metafiles, activate-hibernate"
          description="--> Exports a generated schema to the the database">

      <hibernatetool destdir="${build.dir}">
          <classpath refid="run.classpath"/>
          <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
          <hbm2ddl drop="true" create="true" export="true"
                   outputfilename="helloworld-ddl.sql" format="true"/>
      </hibernatetool>
  </target>

  <target name="run" depends="compile, init-database, copy-metafiles">
      <java fork="true" classname="org.idch.example.HelloWorld" classpathref="run.path"/>
  </target>

</project>


And the basic output from Ant (I can post verbose output if needed).

Code:
Buildfile: build.xml

download-ivy2:

activate-ivy2:
     [echo] Activating Ant tasks for Apache Ivy 2.2.0

-init-ivy:

resolve:
[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
[ivy:retrieve] :: loading settings :: file = XX/build-tools/ivysettings.xml

compile:
     [echo] Compiling with debugging[yes] optimization[no] deprecation[yes]

copy-metafiles:

activate-hibernate:
     [echo] Activating Ant tasks for Hibernate ${hibernate.version}

init-database:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)

BUILD FAILED
XX/hibernate-test/build.xml:76: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

Total time: 3 seconds
neal@idch:hibernate-test$


Many thanks in advance.


Top
 Profile  
 
 Post subject: Re: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
PostPosted: Mon Mar 21, 2011 4:09 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Try with

Code:
<classpath path="${run.classpath}"/>


instead of

Code:
<classpath refid="run.classpath"/>


Don't know if it is the solution, but I think it's worth to try ...


Top
 Profile  
 
 Post subject: Re: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
PostPosted: Wed Mar 23, 2011 10:22 pm 
Newbie

Joined: Fri Mar 18, 2011 11:52 am
Posts: 2
Thanks for the suggestion, turns out that it doesn't make a difference. I'm pretty well stuck on getting the hibernate tools to work nicely from Ant, but SchemaExport works for to create the schema programmatically. As a work around, I'm planning to break that off into a simple executable and run it via <javac>. Not my favorite solution, but it lets me get back to work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.