Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The build file called using <ant> task resets the logging configs of the caller

Two projects: the product (project-A) and the auto benchmark project for A (project-B).

In B's build file, we need to call A's build file to run the build and bundle-with-app-server process like this:

<ant antfile="${build-file-A}" inheritall="false" target="all" />

And, in project B, we have a lot of Ant tasks that output messages using java.util.logging (The JDK Logging Framework).

The problem is, after that line, all the jdk logger outputs disappear.

With debugging, I find that, during the initialzation of project A's build file, a staticly defined thing in project A will run LogManager.readConfiguration(InputStream), which loads a config file that only contains the logger configuration of a single class.

And during readConfiguration, LogManager.reset() will be called; during reset, each handler of each logger will be removed. As <ant> will load the target build file to the same process of the caller, all the handlers will be removed.

So, except the configurated one, every other class that use jdk logger can't output messages due to lack of output handler.

My question is:

Is there any way to solve this problem, other than:

  1. use <exec> to run project A's build file;
  2. write a task to run readConfiguration() to restore the default JDK logging settings from the default configuration file after the <ant> call.
  3. Use ant's own logging framework (Task.log(), etc).

Please note that I can't modify project A to prevent the problem.

like image 673
Dante WWWW Avatar asked Jul 18 '13 08:07

Dante WWWW


People also ask

What is build file in Ant?

Typically, Ant's build file, called build. xml should reside in the base directory of the project. However, there is no restriction on the file name or its location. You are free to use other file names or save the build file in some other location.

How does Ant build system work?

Ant builds are based on three blocks: tasks, targets and extension points. A task is a unit of work which should be performed and constitutes of small atomic steps, for example compile source code or create Javadoc. Tasks can be grouped into targets. A target can be directly invoked via Ant.

What is true about Ant tasks?

Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.

What is build xml used for?

The build. xml file is an Ant script that is created by the PDE to take your plug-in components and combine them into a deployable format. This file compiles and archives your plug-in source code into a single JAR file.


1 Answers

You might be able to create subclass of LogManager and override reset and the two readConfiguration methods to install the handlers you need. Then use the java.util.logging.config.class system property to install your custom code on statup.

like image 57
jmehrens Avatar answered Oct 02 '22 15:10

jmehrens