java.lang.NoSuchMethodError: main
Exception in thread "main" 
---------------------------------代码如下import java.io.*; 
  public class Util extends Object
  {     
    public static int RunThis(String args)
     {
       Runtime rt = Runtime.getRuntime();
       int rc = -1;
       try
       {
       Process p = rt.exec(args);
       int bufSize = 4096;
       BufferedInputStream bis =
       new BufferedInputStream(p.getInputStream(), bufSize);
       int len;
       byte buffer[] = new byte[bufSize];
     
       while ((len = bis.read(buffer, 0, bufSize)) != -1)
         System.out.write(buffer, 0, len);
          rc = p.waitFor();
          }
         catch (Exception e)
         {
           e.printStackTrace();
           rc = -1;
         }
       finally
       {
      return rc ;    
       }
      } 
 }

解决方案 »

  1.   

    没有main函数,运行需要main 函数
      

  2.   

    java.lang.NoSuchMethodError: main 
    Exception in thread "main"  
    没有main函数
    直接运行
    main函数是程序的入口
      

  3.   

    Util , 看名字感觉这不像是程序的入口,LZ应该把用Util 的类贴上来呀。
      

  4.   

    据我夜观天象,楼主贴的类实现如下功能:调用一个可执行程序,捕捉该程序的标准输出并用System.out显示出来直到该程序结束但是楼主试图运行这个类的时候,类文件里面没有提供main入口函数,所以报了java.lang.NoSuchMethodError: main 
    Exception in thread "main"原因大家都知道,运行一个Java类文件,需要该类文件提供public static void main(String [] args)的入口函数其实程序本身没有问题,但是这段代码只是一个工具类,还需要另外一个类来调用RunThis这个静态函数,为了简单起见,我把入口函数直接写到Util类文件里,获得的代码如下import java.io.*;public class Util extends Object { public static void main(String [] args) {
    if (args.length >= 1) {
    int r = Util.RunThis(args[0]);
    System.out.println("Command executed, return code = " + r);
    } else {
    System.out.println("Usage: java Util <command1> <command2> ... <commandN>");
    }
    }

    public static int RunThis(String args) {
    Runtime rt = Runtime.getRuntime();
    int rc = -1;
    try {
    Process p = rt.exec(args);
    int bufSize = 4096;
    BufferedInputStream bis = new BufferedInputStream(p
    .getInputStream(), bufSize);
    int len;
    byte buffer[] = new byte[bufSize]; while ((len = bis.read(buffer, 0, bufSize)) != -1)
    System.out.write(buffer, 0, len);
    rc = p.waitFor();
    } catch (Exception e) {
    e.printStackTrace();
    rc = -1;
    }
    return rc;
    }
    }然后随便写一个批处理文件比如1.bat,在命令行执行:java Util 1.bat
    运行成功
      

  5.   

    是啊 
    本来是没有问题的啊但是LZ是在编译的时候没有问题运行时就有这个异常的这个类本来就不是来运行的而是一个javavbean 被其他的类 方法来调用的LZ不需要去运行这个程序编译就可以了
      

  6.   

    没有MAIN函数.....
    可以按照9楼的去做把
      

  7.   

    --先谢谢上面各位的回答
    --上面的语句是在Oracle里面的Java source,但是不能达到预期的结果,create or replace and compile java source named Util as
    import java.io.*;
    import java.lang.*; 
      public class Util extends Object
      {  
          public static int RunThis(String args)
          {
           Runtime rt = Runtime.getRuntime();
           int rc = -1;
           try
           {
           Process p = rt.exec(args);
           int bufSize = 4096;
           BufferedInputStream bis =
           new BufferedInputStream(p.getInputStream(), bufSize);
           int len;
           byte buffer[] = new byte[bufSize];
         
           while ((len = bis.read(buffer, 0, bufSize)) != -1)
             System.out.write(buffer, 0, len);
              rc = p.waitFor();
              }
             catch (Exception e)
             {
               e.printStackTrace();
               rc = -1;
             }
           finally
             {
               return rc;
             }
         }
     }
     
    /create or replace function RUN_CMD(p_cmd in varchar2) return number
     as
      language java name 'Util.RunThis(java.lang.String) return integer';
    /create or replace procedure RC(p_cmd in varchar2)
     as
       x number;
     begin
       x := run_cmd(p_cmd);
     end;
     
    /
     
    -- 然后进行调用SQL> vari x number;
    SQL> set serveroutput on
    SQL> exec dbms_java.set_output(100000);PL/SQL procedure successfully completedSQL> exec :x := RUN_CMD('ipconfig');
    java.security.AccessControlException: the Permission (java.io.FilePermission <<ALL FILES>> execute) has not been granted to SYSTEM. The PL/SQL to grant this is dbms_java.grant_permission( 'SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'execute' 
    )
      at java.security.AccessControlContext.checkPermission(AccessControlContext.java)
      at java.security.AccessController.checkPermission(AccessController.java)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java)
      at oracle.aurora.rdbms.SecurityManagerImpl.checkPermission(SecurityManagerImpl.java)
      at java.lang.SecurityManager.checkExec(SecurityManager.java)
      at java.lang.Runtime.exec(Runtime.java)
      at java.lang.Runtime.exec(Runtime.java)
      at java.lang.Runtime.exec(Runtime.java)
      at java.lang.Runtime.exec(Runtime.java)
      at Util.RunThis(UTIL.java:11)PL/SQL procedure successfully completed
    x
    ---------
    -1
      

  8.   

    这个是你执行命令的账户在Oracle里面没有足够的权限来运行外部命令啊而且错误提示里面已经给出了怎么赋权限的PL/SQL语句了:
    dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'execute')用osql执行一遍上面的命令,应该就有权限了感觉楼主从来不看错误提示