刚才开了一个帖子,写得太乱了,问题没交代清楚。重新开一个,请帮我看看。请看下面这个简单的例子 这是一个继承了Task类的测试类(Task是ant.jar里面的类) 
这个测试类用来把当前classpath输出。(一个很简单的功能)package com.test;import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;public class Test extends Task{
    
    public void execute() throws BuildException
    {
        String [] classPaths = System.getProperty("java.class.path").toString().split(System.getProperty("path.separator"));
        System.out.println("output classpath:");
        for(String str:classPaths){
            
            System.out.println(str);
        }
        
    }
}然后我写下面这段ant脚本来调用这个测试类 <path id="show.specific.classpath">
      <pathelement location="c:/Test"/>
     </path>    <taskdef name="showclasspath" classname="com.test.Test" classpathref="show.specific.classpath" classpath="c:\Test"/>    <target name="show" description="show classpath">
       <showclasspath>
        
       </showclasspath>
     </target>
但是我这样子调用只能输出我在环境变量中定义了的classpath.我想自己在ant script里面设定classpath(不是环境变量中的)然后通过Test类调用来打印出来。当然这只是一个测试类,在实际的开发中我需要这个 classpath的信息去做一些其他的处理。我应该怎么在这段脚本里面设classpath? ps: 
<classpath.../>这种好像是只能用在 <javac> 标签内部的,这里不能用。
classpathref="show.specific.classpath" 这段配置可以帮助我找到com.test.Test这个类,但不知为什么,它好像不是classpath没有办法打印出来。

解决方案 »

  1.   


    <taskdef name="showclasspath" classname="com.test.Test" classpathref="classpath"/><classpath refid="classpath"/>
    <classpath refid="com.test.Test"/>
    <classpath>
         <pathelement path="${classes}"/>
    </classpath>
    这样编译下有什么问题会?一般classpathref是这样用的
     <javac srcdir="${src}" destdir="${classes}" classpathref="classpath" debug="true"/>
      

  2.   

    <taskdef name="showclasspath" classname="com.test.Test" classpathref="classpath"/><classpath refid="classpath"/>
    <classpath refid="com.test.Test"/>
    <classpath>
         <pathelement path="${classes}"/>
    </classpath>改成 <taskdef name="showclasspath" classname="com.test.Test" classpathref="classpath"/><classpath refid="classpath"/>
    <classpath refid="show.specific.classpath"/>
    <classpath>
         <pathelement path="${classes}"/>
    </classpath>写错了 妈的
      

  3.   


    这个报了Reference class path not found 的错误
    ps:
    我原先的那个配置classpathref="show.specific.classpath"可以很准确的找到com.test.Test这个类(不加类会找不到)。所以我觉得就是应该配置在classpathref里面的。但是没有如预期般输出“c:\Test”