You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2005/09/29 16:14:07 UTC

DO NOT REPLY [Bug 36862] New: - taskdef's class loader and the system class loader

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=36862>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=36862

           Summary: taskdef's class loader and the system class loader
           Product: Ant
           Version: 1.6.5
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: johnny_hujol@vrtx.com


Hi,
just quickly: thank you all for that tool!
Also I searched the DB and did not find anything related to that.

--What I want to do:
Having an portable custom ant repository without having to modify 
the ANT_HOME/lib all the time with new libs. Also if we upgrade 
ANT to a new version, I don't want the developers to mess around
with ANT.
It helps also the automated systems (on 3 != continents) to get the
tasks needed to run the automated JUnit tests and the auto build
systems whereever I want where ANT is installed.
Everything should be smooth for anyone or anything using ANT at work.

--How I did it:
Create a Jar of the custom tasks I have and store this jar with
all the needed jars (like junit<version>.jar) in a directory in CVS.
ANT update using CVS the local copy of that directory
and use the changes recently done to our custom tasks by including the
classpathref to the taskdef tag.

--The problem:
java.lang.NoClassDefFoundError: junit/framework/Test

Solution:
put the junit*.jar in ANT_HOME/lib fixes the problem, but need to modify
ANT_HOME/lib on all the systems and I don't want it (cf what I want to do above)

--Some details now:
0.This is on Mac OS X (10.3.9)
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-233)
Java HotSpot(TM) Client VM (build 1.4.2-56, mixed mode)
Apache Ant version 1.6.5 compiled on June 2 2005

1. I have a task called JUnitWrapperTask that inherits from JUnitTask.
It does not really do fancy stuff.
public class JUnitWrapperTask extends JUnitTask {
    /**
     * Controls output of debugging info *
     */
    protected boolean debug = false;

    protected ArrayList jvmArgumentFileList = new ArrayList();

    public JUnitWrapperTask() throws Exception {
    }

    public void setDebug(boolean on) {
        debug = on;
    }

    public JVMArgumentFile createJvmArgFile() {
        JVMArgumentFile arg = new JVMArgumentFile();
        jvmArgumentFileList.add(arg);
        return arg;
    }

    /**
     * Location of the text file containing jvm args.  File should have 1 arg
     * per line.
     */
    public class JVMArgumentFile {
        protected String jvmArgsFilePath;

        public void setValue(String val) {
            jvmArgsFilePath = val;
            ArrayList jvmArgsList = AntUtilities.getArgumentList(new
File(jvmArgsFilePath), "jvm-args-file", getProject());
            Iterator jvmIter = jvmArgsList.iterator();
            Commandline.Argument jvmArg;
            String value;
            while (jvmIter.hasNext()) {
                value = "-" + (String) jvmIter.next();
                jvmArg = createJvmarg();
                jvmArg.setValue(value);

                if (debug)
                    System.out.println("adding jvm arg '" + value + "'");
            }
        }
    }
}

2. The taskdef definition 
<path id="taskdef.class.path">
<!--    <fileset dir="${ENV.ANT_HOME}/lib">-->
<!--        <include name="*.jar"/>-->
<!--    </fileset>-->
    <fileset dir="${bs.pub.dir}">
        <include name="*.jar"/>
    </fileset>
</path>

<taskdef name="junitWrapper" classname="com.vpharm.ant.JUnitWrapperTask"
classpathref="taskdef.class.path"/>

<target name="echo-cp">
        <property name="titi" refid="taskdef.class.path"/>
        <echo>${titi}</echo>
    </target>
en echo of the classpath

Here is the classpath:
/cvs-storage/junit_3.8.1.jar:/cvs-storage/mytasks_09-28-05-145754.jar

My guess is:
system class loader (SCL) does not find JUnitWrapperTask so delegates to taskdef
class loader (TCL). TCL finds JUnitWrapperTask. 
TCL needs JUnitTask so SCL finds it but then SCL is stupid and does not ask TCL
to look for Test.

My questions:
If u think I did not look enough in the DB point me to the bug# and sorry for that!
Do I do something wrong?
Could someone tell me if this is the normal behavior of the classpathref?
Or in another way why the 2 class loaders don't work together?

Thx for any help.
J

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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