Here's a simple ant class and script that demonstrates the problem.  It uses
the Maven sample.

The ant build script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MavenTest" default="default"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
    <description>
            description
    </description>

        <taskdef name="mavenTestTask"
                 classname="maven.test.task.MavenTestTask" />
        
    <target name="default">
        <echo message="Invoking test class that does nothing but echo the
classloader"/>
        <mavenTestTask/>
        
        <echo message="Invoking maven artifact:pom task"/>
                <artifact:pom id="pom" file="C:/maven-sample/my-app/pom.xml" />

        <echo message="Invoking test class again that does nothing but echo the
classloader"/>
        
        <mavenTestTask/>
        
    </target>
</project>

The simple Ant Task:
package maven.test.task;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 *  Test task demonstrating Maven switching the class loader.
 */
public class MavenTestTask extends Task {

    /* (non-Javadoc)
     * Intentionally not documented. See parent.
     */
    @Override
    public void execute() throws BuildException {
        log("Current Class Loader: " +
Thread.currentThread().getContextClassLoader());
    }
    

The output when run in Ant:
Buildfile: C:\Maven\Test\build.xml
default:
     [echo] Invoking test class that does nothing but echo the classloader
[mavenTestTask] Current Class Loader:
[EMAIL PROTECTED]
     [echo] Invoking maven artifact:pom task
     [echo] Invoking test class again that does nothing but echo the
classloader
[mavenTestTask] Current Class Loader:
[EMAIL PROTECTED]
BUILD SUCCESSFUL
Total time: 871 milliseconds


}



wibbo wrote:
> 
> Hello,
> 
> I'm struggeling with some problems using the Maven ant tasks in the CI
> environment with IBM Jazz. There are some ant tasks for IBM Jazz which
> are handling the connection between the build engine and the Jazz
> server. These Jazz ant tasks are working well as long as I haven't
> used the Maven ant task in the build script. One of the Jazz guys
> analyzed the problem as follows:
> 
> [quote]
> I was able to get some understanding of this problem.  Maven is
> switching out the context class loader on the main Ant thread when
> their task is invoked.   Before the Maven task runs when everything
> works properly...the main ant thread has a class loader of...
> 
> classLoader    Launcher$AppClassLoader  (id=113)
> [EMAIL PROTECTED]
> 
> After the Maven task runs the class loader is now...
> 
> classLoader    RealmClassLoader  (id=166)
> [EMAIL PROTECTED]
> 
> EMF can no longer find the appropriate factory as it delegates to the
> class loader to find the EMF package.  The NPE is then thrown as it
> attempts to use the null factory to get the item type in
> WebServicesSAXXHandler while marshalling the request to the server.  I
> hacked into our task a trap of the class loader before the Maven call
> and then set it back the next time our task executed.  Everything
> worked fine again.  It seems ridiculous that Maven is switching the
> class loader for the main ant thread when their task executes...at the
> very least if this insanity is necessary they should be switching it
> back.
> 
> It appears you can work around this problem by making your pom call
> into Maven before you call any of our ant tasks.  We then appear to
> get initially loaded into their class loader correctly and everything
> works ok.
> [/quote]
> 
> Why is the Maven ant task switching the class loader for the main ant
> thread? Is this a bug or works as designed?
> 
> Thanks for your feedback!
> 
> Regards,
> Thomas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Using-Maven-Ant-Tasks-in-a-CI-Environment-with-IBM-Jazz-tp16556859s177p16568639.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to