Making listener visible to Ant

View: New views
3 Messages — Rating Filter:   Alert me  

Making listener visible to Ant

by wheleph :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone.
I've created my own listener CustomXmlLogger that is a child of XmlLogger and packed it in VCS.jar. I don't want to copy it to ANT_HOME/lib so I tried to include a reference to the archive in my Ant call.
But I've got a problem. When I launch a build Ant indicates on LinkageError:

"C:\Program files\Java\jdk1.5.0_08\bin\java.exe" -classpath
 c:\bin\apache-ant-1.7.0\lib\ant-launcher.jar;VCS.jar
 -DXmlLogger.file=build_tes
t_log.xml -DXmlLogger.level=WARN -Dant.home=c:\bin\apache-ant-1.7.0 org.apache.t
ools.ant.launch.Launcher -listener com.kvazarmicro.umc.vcs.utils.CustomXmlLogger

Buildfile: build.xml

BUILD FAILED
Class com.kvazarmicro.umc.vcs.utils.CustomXmlLogger could not be loaded because
of an invalid dependency.


When I added ant.jar the error was different:
D:\home\UMC\.garbage>"C:\Program files\Java\jdk1.5.0_08\bin\java.exe" -classpath
 c:\bin\apache-ant-1.7.0\lib\ant-launcher.jar;c:\bin\apache-ant-1.7.0\lib\ant.jar;VCS.jar
 -DXmlLogger.file=build_test_log.xml -DXmlLogger.level=WARN -Dant.home=
c:\bin\apache-ant-1.7.0 org.apache.tools.ant.launch.Launcher -listener com.kvazarmicro.umc.vcs.utils.CustomXmlLogger
Buildfile: build.xml

test:
   [delete] Deleting directory D:\home\UMC\.garbage\build
    [mkdir] Created dir: D:\home\UMC\.garbage\build
    [javac] Compiling 1 source file to D:\home\UMC\.garbage\build

BUILD FAILED
D:\home\UMC\.garbage\build.xml:14: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program files\Java\jdk1.5.0_08\jre"

My JAVA_HOME is set to "C:\Program files\Java\jdk1.5.0_08" and Ant finds compiler perfectly if I don't use my listener.

So I have a question: how can I use a custom listener not copying it in ANT_HOME/lib?

Source of the listener:
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.XmlLogger;

public class CustomXmlLogger extends XmlLogger {
        @Override
        public void buildStarted(BuildEvent event) {
                super.buildStarted(event);
                String levelStr = System.getProperty("XmlLogger.level");
                if (levelStr != null) {
                        int level;
                        if (levelStr.equalsIgnoreCase("ERR")) {
                                level = Project.MSG_ERR;
                        } else if (levelStr.equalsIgnoreCase("WARN")) {
                                level = Project.MSG_WARN;
                        } else if (levelStr.equalsIgnoreCase("INFO")) {
                                level = Project.MSG_INFO;
                        } else if (levelStr.equalsIgnoreCase("VERBOSE")) {
                                level = Project.MSG_VERBOSE;
                        } else {
                                level = Project.MSG_DEBUG;
                        }
                        setMessageOutputLevel(level);
                }
        }
}

Re: Making listener visible to Ant

by Stefan Bodewig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 10 Jul 2008, <wheleph@...> wrote:

> Hello everyone.  I've created my own listener CustomXmlLogger that
> is a child of XmlLogger and packed it in VCS.jar. I don't want to
> copy it to ANT_HOME/lib so I tried to include a reference to the
> archive in my Ant call.  But I've got a problem. When I launch a
> build Ant indicates on LinkageError:

This is because your class references classes from ant.jar that will
not be on the system classloader when you start ant via

>
> "C:\Program files\Java\jdk1.5.0_08\bin\java.exe" -classpath
>  c:\bin\apache-ant-1.7.0\lib\ant-launcher.jar;VCS.jar
> -DXmlLogger.file=build_tes
> t_log.xml -DXmlLogger.level=WARN -Dant.home=c:\bin\apache-ant-1.7.0
> org.apache.t
> ools.ant.launch.Launcher -listener
> com.kvazarmicro.umc.vcs.utils.CustomXmlLogger

while your class is on the system classloader.

Alternatives to ANT_HOME/lib are $HOME/.ant/lib and the -lib command
line argument.

I don't see any other option ATM.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: Making listener visible to Ant

by wheleph :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, Stefan.

-lib option works like a charm.
LightInTheBox - Buy quality products at wholesale price!