简体   繁体   English

Java编译器ASP.NET

[英]Java Compiler ASP.NET

I'm trying to make an online compiler for java using ASP.NET C# 我正在尝试使用ASP.NET C#为Java创建在线编译器

Process p=new Process();
p.StartInfo.FileName = "C:\\Program files\\Java\\bin\\javac.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "C:\\Hello.java";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardOutput.ReadToEnd();
p.WaitForExit();

I run javac.exe to compile Hello.java, but the process isn't allowed by ASP.NET to write Hello.class to disk 我运行javac.exe来编译Hello.java,但是ASP.NET不允许该过程将Hello.class写入磁盘

But on doing it manually through cmd.exe without using ASP.NET or progmatically using C# only it runs perfectly 但是在不使用ASP.NET的情况下通过cmd.exe手动执行或仅使用C#进行编程时,它运行良好

Can you help me make an online java compiler using ASP.NET or PHP for compiling Algorithmic assignments? 您能帮我用ASP.NET或PHP制作在线Java编译器来编译算法分配吗?

This is a permissions problem - you have two options: 这是一个权限问题-您有两个选择:

  • Change the application pool identity to an account that has write permissions 将应用程序池标识更改为具有写权限的帐户
  • Give write permissions to the current application pool identity account 授予当前应用程序池标识帐户的写入权限

you should configure the access rights for the ASPNET user, this changes a bit depending on which version of IIS and Windows Server the web application runs. 您应该为ASPNET用户配置访问权限,这取决于Web应用程序运行的IIS和Windows Server版本。

Consider to store the output data locally on the server's disk on a proper location, not directly C or any system folder. 考虑将输出数据本地存储在服务器磁盘上的适当位置,而不是直接C或任何系统文件夹中。 let's say C:\\JavaOutput\\ then give read/write permissions to the ASPNET user to that folder. 假设C:\\JavaOutput\\然后将ASPNET用户的读/写权限授予该文件夹。

This is a permission problem. 这是一个权限问题。 You need to allow full permissions to c:\\ for the ASP.NET USER\\IISUSER. 您需要为ASP.NET USER \\ IISUSER授予对c:\\的完全权限。 That's obviously a WRONG approach. 这显然是错误的方法。

Your working directory should be the directory in which your web application sits. 您的工作目录应该是Web应用程序所在的目录。

Where on the disk does the compiler try to store Hello.class? 编译器尝试在磁盘上的哪个位置存储Hello.class? Chances are, it's in a folder where the ASP.NET process has no permissions to write. 它可能位于ASP.NET进程没有写权限的文件夹中。

Some tips: 一些技巧:

1) Find out what permissions the ASP.NET worker process has. 1)找出ASP.NET辅助进程具有哪些权限。 If using IIS, check out the identity of the ApplicationPool it's running under. 如果使用IIS,请检查正在其下运行的ApplicationPool的身份。 Chances are it's running under a limited profile. 很有可能它的配置文件受到限制。

2) Find a folder where the ASP.NET worker process can write to. 2)找到一个ASP.NET工作进程可以写入的文件夹。 This should probably be in a directory under the application root (~), or in some TEMP folder. 这可能应该在应用程序根目录(〜)下的目录中,或在TEMP文件夹中。

3) Check if the javac command-line allows you to specify an explicit output directory. 3)检查javac命令行是否允许您指定显式输出目录。 If not, use p.StartInfo.WorkingDirectory to specify a working folder for the process, which will probably make javac output to the specified folder. 如果不是,请使用p.StartInfo.WorkingDirectory为该进程指定一个工作文件夹,这可能会将javac输出到指定的文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM