Apache Ant自定义任务:未找到类类本身的异常

时间:2014-11-17 20:35:55

标签: java ant classloader

我已经使用两种模式构建了一个应用程序:

  1. 从命令行使用
  2. 使用Ant
  3. 它在命令行中运行良好但是从ANT可以看出错误是令人惊讶的,Java加载器无法找到主类,并且从主类中抛出了异常!

    主要课程的摘录

    package hpms.app.mon.client;
    import ....;
    public class MonitorMainFrame extends Application implements ProcessListener {
       ....
       public static void main( String[] args ) throws Exception {
          final Class<?> c = Class.forName( MonitorMainFrame.class.getName());
          /* The class was found and we print the constructor */
          System.err.println( c.getConstructor());
          launch( args );                                    // line 544
       }
    }
    

    构建执行

    Buildfile: D:\dev\java\2014\hpms.app.mon\build.xml
    
    compile-sample:
    
    run-servers:
    
    BUILD SUCCESSFUL
    Total time: 1 second
    Buildfile: D:\dev\java\2014\hpms.app.mon\build.xml
    
    compile-sample:
    
    run-client:
    [monitor-client] public hpms.app.mon.client.MonitorMainFrame() throws java.lang.Exception  <==== Trace of the constructor object
    
    BUILD FAILED
    D:\dev\java\2014\hpms.app.mon\build.xml:112: java.lang.RuntimeException: java.lang.ClassNotFoundException: hpms.app.mon.client.MonitorMainFrame
            at javafx.application.Application.launch(Application.java:260)
            at hpms.app.mon.client.MonitorMainFrame.main(MonitorMainFrame.java:544)
            at hpms.app.mon.client.ant.AntTask.execute(AntTask.java:79)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    

    的build.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="test" default="jar">
       ...
    
       <taskdef
          onerror  ="ignore"
          name     ="monitor-client"
          classpath="bin"
          classname="hpms.app.mon.client.ant.AntTask" />
    
       <target name="run-client" depends="compile-sample" description="...">
          <monitor-client
             minimized="true"
             autostart="true">
             ...
    

    如何找不到类可以从类本身抛出异常?

    我认为Java类加载器已经加载了类,而Ant类加载器还没有...

0 个答案:

没有答案