从ASP.NET MVC运行Java不起作用

从ASP.NET MVC运行Java不起作用,java,c#,asp.net,asp.net-mvc-5,Java,C#,Asp.net,Asp.net Mvc 5,当我尝试从cmd运行Java代码时,它是有效的。但当我从ASP.NET MVC应用程序运行它时,我总是得到: 找不到或无法加载main。 这是我正在使用的代码: Process p = new Process(); p.StartInfo.FileName = "C:/Program Files/Java/jdk1.8.0_20/bin/java.exe"; p.StartInfo.UseShellExecute = false;

当我尝试从cmd运行Java代码时,它是有效的。但当我从ASP.NET MVC应用程序运行它时,我总是得到: 找不到或无法加载main。 这是我正在使用的代码:

Process p = new Process();
            p.StartInfo.FileName = "C:/Program Files/Java/jdk1.8.0_20/bin/java.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.Arguments = "E:/Atypon/TE1/src/Assignment3.DateTest";
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardError = true;
            p.Start();
            string result = p.StandardError.ReadToEnd();
            p.WaitForExit();

我做错了什么?

类名的参数可能是错误的,也许应该是错误的

p.StartInfo.Arguments = "E:/Atypon/TE1/src/Assignment3.DateTest.class"; 

看起来我必须指定工作目录中主类的路径,而不是参数:

 public ActionResult Run()
    {
        Process p = new Process();
        p.StartInfo.FileName = "C:/Program Files/Java/jdk1.8.0_20/bin/java.exe";
        p.StartInfo.UseShellExecute = false;
        //path to dir
        p.StartInfo.WorkingDirectory = "E:/Atypon/TE1/src";
        //packageName.MainClass
        p.StartInfo.Arguments = "Assignment3.DateTest";
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.RedirectStandardError = true;
        p.Start();
        string result = p.StandardOutput.ReadToEnd();
        p.WaitForExit();
        return View("Index",(Object)result);
    }

可能您没有提供完整的文件名。通常java runnables的文件以.class或.jar结尾。从cmd运行java时,添加扩展名是导致此错误的原因之一。但是我试过了,但没有成功。在用C语言运行它之前,如果你只是在命令行执行它会怎么样?C:/Program Files/Java/jdk1.8.0_20/bin/Java.exe E:/Atypon/TE1/src/Assignment3.DateTest在尝试从C执行此操作之前先执行此操作。我收到了相同的错误。即使我使用javae:/Atypon/TE1/src/Assignment3.DateTest,它仍然可以工作。如果我从Java程序目录中使用它,你能使用后一个版本吗?我试过了,但没有成功。实际上,我曾经读过adding.class生成这个错误。