Where do I put my log4j.properties file for the jrc task in Ant?

 Hello,

I'd like to configure a log4j appender for the compilation of my .jrxml files, i.e. the jrc Ant task. I'm sure that I have to put the log4j.properties file on my classpath. I'm unsure how to specify that in my build.xml (sse code).

When I do include my log4j.properties file in my classpath for the jrc task, I get a ZipException because Ant is expecting the properties file to be a jar or zip:

      [jrc] Compiling 2 report design files.
Unable to obtain resource from C:\\Documents and Settings\\SSolomon\\my-report-mana
ger\\resources\\log4j.properties: java.util.zip.ZipException: error in opening zip
 file
      [jrc] Unable to obtain resource from C:\\Documents and Settings\\SSolomon\\my
-report-manager\\resources\\log4j.properties:
      [jrc] java.util.zip.ZipException: error in opening zip file
      [jrc]     at java.util.zip.ZipFile.open(Native Method)
      [jrc]     at java.util.zip.ZipFile.<init>(ZipFile.java:127)
      [jrc]     at java.util.jar.JarFile.<init>(JarFile.java:135)
      [jrc]     at java.util.jar.JarFile.<init>(JarFile.java:99)
      [jrc]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLo
ader.java:1002)
      [jrc]     at org.apache.tools.ant.AntClassLoader.getResource(AntClassLoade
r.java:883)
 
What is the proper way to put the log4j.properties file on the classpath for the jrc task?
 
Thanks
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ProjectManager" default="default" basedir=".">
 
    <!-- Define the classpath used for report compilation -->
    <path id="jrc.classpath">
        <fileset dir="lib" includes="*.jar"/>
    </path>
 
    <path id="log4j.classpath">
        <file file="resources/log4j.properties"/>
    </path>
 
    <target name="compile" description="Compile all Jasper Reports Definitions">
	<mkdir dir="./build/reports"/>
	<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
               <classpath refid="jrc.classpath"/>
               <classpath refid="log4j.classpath"/>
	</taskdef>
        <jrc destdir="./build/reports">
            <src>
                <fileset dir="src/main/jasperreports">
                    <include name="*.jrxml"/>
                </fileset>
            </src>
            <classpath refid="jrc.classpath"/>
        </jrc>
    </target>
 
    <target name="clean">
        <delete dir="./build" />
    </target>
 
</project>
</td></tr></tbody></table>
slsolomon's picture
Joined: Jan 18 2011 - 8:18pm
Last seen: 12 years 8 months ago

1 Answer:

Create a log4j.properties file, create a jar file (using the jar command) containing the log4j.properties file at the root of the jar. Include this jar in the jrc task classpath. Et voila, compiler logging.

slsolomon's picture
Joined: Jan 18 2011 - 8:18pm
Last seen: 12 years 8 months ago
Feedback