public class AAA extends TaskTemplate
{
 public void execute() throws BuildException
 {
   System.out.println("ddddd");
 }
}
我在build.xml中通过下面这段代码来调用这个java类,没有问题。<taskdef name="AAA" classname="com.test.AAA" />     <target name="AAA_test" description="Run aaa">
       <AAA classpath="${test.path};${test.path}\test.jar;${env.CLASSPATH}">
       <fileset dir="${basedir}\source">
       </fileset>
       </AAA>
 </target>但是我要怎么在eclipse的Debug中加一个应用来调试这个代码呢?我的思路是它坑定要通过org.apache.tools.ant.launch.AntMain 调用这个应用程序的,所以我就新建了一个java application,然后在main class里面写了org.apache.tools.ant.launch.AntMain 然后在arugment里面写AAA_test
但是报错了。
java.lang.NoSuchMethodError: main
Exception in thread "main" ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 ["util.c",L765]
JDWP exit error JVMTI_ERROR_INTERNAL(113): 
有谁知道这种情况要怎么解决吗?
ps:重申一下我的要求,我想在eclipse中调试一个继承TaskTemplate的java类,一般情况下这种类是要通过build.xml来条用的,但是这样就不能调试了,我想要调试代码,不通过ant build.xml去call,应该怎么做?

解决方案 »

  1.   

    如果只是想调试AAA 这个类是否满足你的要求的话,可以在AAA里面写main函数啊。
    public class AAA extends TaskTemplate
    {
     public void execute() throws BuildException
     {
       System.out.println("ddddd");
     }
     public static void main()
     {
       AAA test = new AAA();
       test.execute();
     }
    }
      

  2.   

    再补充问一下,通过这种方式调用java类,只能用
    <fileset dir="${basedir}\source">
    </fileset>
    来传递参数吗,这样只能传文件的名字,有没有办法传递其他的参数,比如字符串
      

  3.   

    我已经知道怎么调试了
    新建 java Application
    在main class里写org.apache.tools.ant.Main
    然后参数里面写 -f “build.xml” taskname================================================
    但是我还是不知道怎么通过build.xml文件把一些参数传给java类。
    有没有高手出来顶一下
      

  4.   

    用org.apache.tools.ant.launch.AntMain 来执行程序?
    节选一段ant in atcion的话,我觉得很有指导意义的。Although Ant is a great build tool, there are some places where it isn’t appropriate.
    Ant is not the right tool to use outside of the build process. Its command line and
    error messages are targeted at developers who understand English and Java programming.
    You should not use Ant as the only way end-users can launch an application.
    Some people do this: they provide a build file to set up the classpath and run a Java
    program, or they use Ant to glue a series of programs together. This works until there’s
    a problem and Ant halts with an error message that only makes sense to a developer.