java - 使用另一个Java文件运行Java文件时出错

标签 java error-handling

我实际上正在尝试在Windows中使用另一个Java文件来运行我的Java文件....这是我的代码:

private static void printLines(String name, InputStream ins) throws Exception {
    String line = null;
    BufferedReader in = new BufferedReader(
        new InputStreamReader(ins));
    while ((line = in.readLine()) != null) {
        System.out.println(name + " " + line);
    }
  }

  private static void runProcess(String command) throws Exception {
      String s=System.getProperty("user.dir");
      s="C:\\Users\\HP\\Downloads\\apache-tomcat-7.0.54-windows-x64\\apache-tomcat-7.0.54\\webapps\\Mazil4.0\\WEB-INF\\classes";
  File workingDir = new File(s);
  System.out.println(q);
  //new Foo().nonStaticMethod();
Process pro = Runtime.getRuntime().exec(command,null,workingDir);

printLines(command + " stdout:", pro.getInputStream());
printLines(command + " stderr:", pro.getErrorStream());
pro.waitFor();
System.out.println(command + " exitValue() " + pro.exitValue());


 }


  public static void mai(String[] args) {

      String[] credentials=new String[4];int k=0;
      for (String s: args) {
          System.out.println(s);
        credentials[k]=s;k++;
    if(k==4)
    break;
      }


    try {
      //runProcess("javac test2.java");
        //thread foo=new thread();
      runProcess("java mainclasses.emaildownload "+credentials[0]+" "+credentials[1]+" "+credentials[2]+" "+credentials[3]+" ");

    } catch (Exception e) {
      e.printStackTrace();
    }System.out.println("hI");
  }

我通过使用workingDir给出了类的位置...并且我的文件路径是:
C:\Users\HP\Downloads\apache-tomcat-7.0.54-windows-x64\apache-tomcat-7.0.54\webapps\Mazil4.0\WEB-INF\classes\mainclasses\emaildownload.class

包名称是mainclasses。但是它仍然给出错误:
could not find or load main class mainclasses.emaildownload

可能是为什么?

最佳答案

在这一行:

public static void mai(String[] args) {

是“n”缺失。

改成
public static void main(String[] args) {

关于java - 使用另一个Java文件运行Java文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24475830/

相关文章:

java - JList - 使用垂直滚动条而不是垂直环绕方向的水平滚动条?

android - 预览未在Android Studio 3.1.4中显示

python - Python Selenium-尝试除外的无效语法错误

flutter - 调用null和boolean表达式的方法不能为null

java - PLAY 中嵌套对象的自动 save()!日本PA

java - 如何在字符串后命名对象引用

java - MentaContainer 上的自动布线不起作用?

javascript - 是否可以防止将特定的 JavaScript 错误写入控制台?

R:将 `warning()` 的输出格式化为超过一行的选项列表

java - 在没有 setZOrderOnTop(true) 的情况下使 SurfaceView 透明