0

i want to execute a precompiled java class file from a MVC action.the class file is placed with in the C# project folder. But Still it throws File Not Found Exception.

`Process myProcess = new Process();

myProcess.StartInfo.UseShellExecute = false;
//File not Found Exception Appears Here
myProcess.StartInfo.FileName = @"java JDKTest2";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();`
Emu Malik
  • 101
  • 1
  • 8
  • You need to make sure your path to the java.exe is specified correctly see if [this link](http://stackoverflow.com/questions/3038140/how-to-determine-windows-java-installation-location) helps – spinalfrontier Apr 29 '17 at 07:21

1 Answers1

0

You need to pack java class to a jar and call it like this:

myProcess.StartInfo.UseShellExecute = false;
//File not Found Exception Appears Here
myProcess.StartInfo.FileName = "java";
myProcess.StartInfo.Arguments = @"-jar JDKTest2.jar";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();

Also make sure the paths to java and JDKTest2.jar are known in this context or switch to absolute path.

admax
  • 1,671
  • 2
  • 16
  • 23
  • it worked ! but now the process returns exit code 1. – Emu Malik May 04 '17 at 16:13
  • I am Working on a java Online compiler as semester project ! I created a similar application in java servlets ! which works fine ! but in MVC c# I am barely able to run a jar. – Emu Malik May 04 '17 at 16:19