Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 50041 invoked from network); 23 Feb 2010 17:17:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Feb 2010 17:17:19 -0000 Received: (qmail 45912 invoked by uid 500); 23 Feb 2010 17:17:17 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 45844 invoked by uid 500); 23 Feb 2010 17:17:17 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 45834 invoked by uid 99); 23 Feb 2010 17:17:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Feb 2010 17:17:17 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rhino1@sympatico.ca designates 209.226.175.184 as permitted sender) Received: from [209.226.175.184] (HELO tomts22-srv.bellnexxia.net) (209.226.175.184) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Feb 2010 17:17:07 +0000 Received: from toip3.srvr.bell.ca ([209.226.175.86]) by tomts22-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20100223171646.HHQC22975.tomts22-srv.bellnexxia.net@toip3.srvr.bell.ca> for ; Tue, 23 Feb 2010 12:16:46 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApEBABmZg0tMRyqx/2dsb2JhbAAH2V+EbASDFQ Received: from bas8-london14-1279732401.dsl.bell.ca (HELO [127.0.0.1]) ([76.71.42.177]) by toip3.srvr.bell.ca with ESMTP; 23 Feb 2010 12:05:09 -0500 Message-ID: <4B840D7A.3040203@sympatico.ca> Date: Tue, 23 Feb 2010 12:16:42 -0500 From: Rhino User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: ant-user Subject: Logging problem using Ant Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 100223-1, 2010-02-23), Outbound message X-Antivirus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org Hi, I am having an odd problem using Ant. Whenever my Java program tries to create a new instance of java.util.logging.FileHandler, I get a java.io.IOException that says "Couldn't get lock for log2\baz.log.xml". The weird part of this problem is that I get this error when I am running Ant but NOT when I simply execute the program in Eclipse. I am running Eclipse 3.5.1 Galileo on Windows XP with SP 2. This version of Eclipse contains Ant 1.7.1. When I run the program from an Ant script within Eclipse OR from the Windows command line (using Ant 1.8.0), I get the error that I mentioned. However, when I run the program as a Java application from within Eclipse, it works fine and does not generate this error. I'm baffled and would appreciate some help to prevent this error. I've created a simple example and an Ant build file that illustrates the problem. My project is called Logging and it is a regular Java project in Eclipse. Within the package com.foo.baz2, which is in my src folder in the Logging project, I have the following classes: * Supremo, which is the driver program * Alpha, which is the class invoked from Supremo which actually writes to the log file Here is the source code for Supremo: ================================ package com.foo.baz2; import java.io.File; import java.io.IOException; import java.util.logging.FileHandler; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; public class Supremo { /** * The name of this class. */ private final String CLASS_NAME = getClass().getName(); /** * The logger that will log error messages in this class. */ private Logger logger = null; /** * The file handler used by this logger. */ private Handler logFileHandler = null; /** * @param args */ public static void main(String[] args) { new Supremo(); System.out.println("=== Supremo ends ==="); } public Supremo() { configureLogger(); new Alpha(logger).writeText(); } /** * Method configureLogger() configures the logger(s) used by this program. * *

Additional comments about method configureLogger().

*/ private final void configureLogger() { String METHOD_NAME = "configureLogger()"; //$NON-NLS-1$ /* Create the logger. */ this.logger = Logger.getLogger(CLASS_NAME); /* Create a file handler for the logger. */ String logFile = "log2" + File.separator + "baz.log.xml"; try { this.logFileHandler = new FileHandler(logFile); } catch (IOException io_excp) { System.err.println(this.CLASS_NAME + "." + METHOD_NAME + " - Couldn't create FileHandler for logger " + this.CLASS_NAME + " using file " + logFile + ". Error: " + io_excp); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ io_excp.printStackTrace(); return; } this.logger.addHandler(this.logFileHandler); /* Set the logging level. */ this.logger.setLevel(Level.FINEST); } } ================================ Here is the source code for Alpha: ================================ package com.foo.baz2; import java.util.logging.Logger; public class Alpha { /** * The name of this class. */ private final String CLASS_NAME = getClass().getName(); /** * The logger that will log error messages in this class. */ private Logger logger = null; public Alpha() { super(); } public Alpha(Logger logger) { super(); this.logger = logger; } public void writeText() { final String METHOD_NAME = "writeText()"; System.out.println(CLASS_NAME); logger.entering(CLASS_NAME, METHOD_NAME); } } ================================ Here is the build file, which is named build2.xml: ================================ Compile and run the Baz program. ================================ Here is the output from the Ant build when it is run in Eclipse using Ant 1.7.1: ================================ Buildfile: C:\eclipse\workspace\Logging\xml\build2.xml compile: run: [echo] Run the program. [java] com.foo.baz2.Supremo.configureLogger() - Couldn't create FileHandler for logger com.foo.baz2.Supremo using file log2\baz.log.xml. Error: java.io.IOException: Couldn't get lock for log2\baz.log.xml [java] java.io.IOException: Couldn't get lock for log2\baz.log.xml [java] at java.util.logging.FileHandler.openFiles(Unknown Source) [java] at java.util.logging.FileHandler.(Unknown Source) [java] at com.foo.baz2.Supremo.configureLogger(Supremo.java:61) [java] at com.foo.baz2.Supremo.(Supremo.java:40) [java] at com.foo.baz2.Supremo.main(Supremo.java:33) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [java] at java.lang.reflect.Method.invoke(Unknown Source) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152) [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:764) [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218) [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132) [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105) [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [java] at java.lang.reflect.Method.invoke(Unknown Source) [java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) [java] at org.apache.tools.ant.Task.perform(Task.java:348) [java] at org.apache.tools.ant.Target.execute(Target.java:357) [java] at org.apache.tools.ant.Target.performTasks(Target.java:385) [java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337) [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1306) [java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) [java] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32) [java] at org.apache.tools.ant.Project.executeTargets(Project.java:1189) [java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423) [java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137) [java] com.foo.baz2.Alpha [java] com.foo.baz2.Beta [java] com.foo.baz2.Gamma [java] === Supremo ends === buildall: [echo] The build has ended successfully. BUILD SUCCESSFUL Total time: 313 milliseconds ================================ Does anyone know why I'm having this problem? -- Rhino --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org