ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: Hibernate & Log4j
Date Wed, 28 Jul 2004 03:41:04 GMT
You're missing the obvious.  Add to your path...

<pathelement location="${dir.src}/config"/>


Keep in mind, the following properties file will *not* be found in the 
classpath...

C:\1-AbundantPlanet\ap\src\config\log4j.properties;

But it will if you do this...

C:\1-AbundantPlanet\ap\src\config;


Always remember to add directories and jars (which acts as a directory 
structure) to the classpath, not files.


Jake


At 05:50 PM 7/27/2004 -0700, you wrote:

>Hello,
>
>I hope someone here can give me a hint. I've been banging my head
>against a wall trying to get Hibernate tasks to see a log4j.properties
>or log4j.xml file for days. I'm using Ant (of course) for the build,
>so I thought someone here might have a suggestion.
>
>I'm new to Hibernate, but have used Log4j before without difficulty.
>Hibernate's manual says you need to put the log4j.jar and a properties
>file in the classpath, and then everything should work. This has not
>been my experience.
>
>-----------------------------------------------------------------
>
>         The bit of Hibernate code I've focused on is hbm2java, which
>         generates Java source from hbm.xml templates. Following James
>         Elliott's nice intro book, the target is called <codegen>:
>
>   <target name="codegen" depends="prepare-configs"
>     description="Generate Java code from hbm.xml files.">
>
>     <taskdef name="hbm2java"
>       classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
>       classpathref="classpath.project"/>
>
>     <hbm2java output="${dir.src}">
>       <classpath>
>         <pathelement path="${classpath.project}"/>
>       </classpath>
>       <fileset dir="${dir.src}">
>         <include name="**/*.hbm.xml"/>
>       </fileset>
>     </hbm2java>
>   </target>
>
>
>         This *does* generate the file expected, but it complains:
>
>codegen:
>  [hbm2java] Processing 1 files.
>  [hbm2java] Building hibernate objects
>  [hbm2java] log4j:WARN No appenders could be found for logger
>             (net.sf.hibernate.util.DTDEntityResolver).
>  [hbm2java] log4j:WARN Please initialize the log4j system properly.
>
>
>
>  My attempts to get hbm2java to see a Log4j properties file:
>
>  1. Copied log4j.properties (from Hibernate's demo) throughout
>  the build directory ('*' marks dirs with properties file):
>
>
>    ap *               <--[build.xml is here]
>    |-build *
>    |  |-classes *
>    |     |-org *
>    |        |-apnp *
>    |           |-nrd *
>    |-lib *
>    |-src *
>    |  |-config *
>    |  |-org *
>    |     |-apnp *
>    |        |-nrd *
>
>
>
>  2. Altered classpath.project to include many locations:
>
>   <path id="classpath.project">
>     <pathelement location="${dir.src}"/>
>     <pathelement location="${dir.build}"/>
>     <pathelement location="${dir.build.classes}"/>
>     <pathelement location="${dir.build.classes}/org/apnp/nrd"/>
>
>     <fileset dir="${dir.src}/config">
>       <include name="*.properties"/>
>       <include name="*.dtd"/>
>       <include name="*.xml"/>
>     </fileset>
>     <fileset dir="${dir.lib}">
>       <include name="*.jar"/>
>       <include name="*.bat"/>
>     </fileset>
>     <fileset dir="${tomcat.lib}">
>       <include name="servlet-api.jar"/>
>     </fileset>
>   </path>
>
>
>
>  3. Made hbm2java use this classpath both as source for taskdef
>  and for running (as shown above):
>
>     <taskdef name="hbm2java"
>       classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
>       classpathref="classpath.project"/>
>
>     <hbm2java output="${dir.src}">
>       <classpath>
>         <pathelement path="${classpath.project}"/>
>       </classpath>
>       <fileset dir="${dir.src}">
>         <include name="**/*.hbm.xml"/>
>       </fileset>
>     </hbm2java>
>
>
>
>  4. Had codegen display 'classpath.project' between hbm2java
>  taskdef and running hbm2java:
>
>     <pathconvert targetos="windows" property="classpathProject"
>       refid="classpath.project"/>
>     <echo>classpathProject = ${classpathProject}  </echo>
>
>         Which shows (adding line breaks):
>
>[echo] classpathProject =
>C:\1-AbundantPlanet\ap\src;
>C:\1-AbundantPlanet\ap\build;
>C:\1-AbundantPlanet\ap\build\classes;
>C:\1-AbundantPlanet\ap\src\config\hibernate-configuration-2.0.dtd;
>C:\1-AbundantPlanet\ap\src\config\hibernate-mapping-2.0.dtd;
>C:\1-AbundantPlanet\ap\src\config\hibernate.cfg.xml;
>C:\1-AbundantPlanet\ap\src\config\hibernate.properties;
>C:\1-AbundantPlanet\ap\src\config\log4j.dtd;
>C:\1-AbundantPlanet\ap\src\config\log4j.properties;           <<<<
>C:\1-AbundantPlanet\ap\src\config\log4j.xml;                  <<<<
>C:\1-AbundantPlanet\ap\src\config\tomcat.properties;
>C:\1-AbundantPlanet\ap\src\config\tomcatTasks.properties;
>C:\1-AbundantPlanet\ap\lib\SchemaExport.bat;
>C:\1-AbundantPlanet\ap\lib\SchemaUpdate.bat;
>C:\1-AbundantPlanet\ap\lib\cglib-full-2.0.1.jar;
>C:\1-AbundantPlanet\ap\lib\class2hbm.bat;
>C:\1-AbundantPlanet\ap\lib\commons-collections-2.1.jar;
>C:\1-AbundantPlanet\ap\lib\commons-lang-1.0.1.jar;
>C:\1-AbundantPlanet\ap\lib\commons-logging-1.0.3.jar;
>C:\1-AbundantPlanet\ap\lib\ddl2hbm.bat;
>C:\1-AbundantPlanet\ap\lib\dom4j-1.4.jar;
>C:\1-AbundantPlanet\ap\lib\ehcache-0.7.jar;
>C:\1-AbundantPlanet\ap\lib\hbm2java.bat;
>C:\1-AbundantPlanet\ap\lib\hibernate-2.1.4.jar;
>C:\1-AbundantPlanet\ap\lib\hibernate-tools.jar;
>C:\1-AbundantPlanet\ap\lib\log4j-1.2.8.jar;                   <<<<
>C:\1-AbundantPlanet\ap\lib\mysql-connector-java-3.0.14.jar;
>C:\1-AbundantPlanet\ap\lib\odmg-3.0.jar;
>C:\Apache\Tomcat\Tomcat50\common\lib\servlet-api.jar
>
>
>
>  The log4j.properties file from Hibernate's distribution, is
>  simple ('warn' changed to 'debug'; comments and file appender
>  deleted):
>
>log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>log4j.appender.stdout.Target=System.out
>log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L -
>%m%n
>
>log4j.rootLogger=debug, stdout
>log4j.logger.net.sf.hibernate=debug
>log4j.logger.net.sf.hibernate.type=info
>log4j.logger.net.sf.hibernate.tool.hbm2ddl=debug
>
>
>
>  The log4j.xml file, is also simple (file appender deleted):
>
><?xml version="1.0" encoding="UTF-8" ?>
><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>
><log4j:configuration debug="true"
>   xmlns:log4j="http://jakarta.apache.org/log4j/">
>
>   <!-- System.out appender. -->
>   <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
>     <param name="Target" value="System.out"/>
>     <layout class="org.apache.log4j.PatternLayout">
>       <param name="ConversionPattern"
>         value="%d{HH:mm:ss} [%5.5t] %-5p [%-20.30c{1}] %x - %m\n"/>
>     </layout>
>   </appender>
>
>   <!-- Root logger. Sends all debug-and-up messages to console. -->
>   <root>
>     <priority value="debug" />
>     <appender-ref ref="ConsoleAppender" />
>   </root>
>
></log4j:configuration>
>
>
>
>  I'd be very grateful for any ideas on what else to test, or
>  how else to look at the problem.
>
>  Oh yes, Ant: 1.6.1. JVM: j2sdk-1.4.2
>
>  Thanks again,
>
>  William BC Crandall
>  bc.crandall [around] earthlink.net
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message