You will need to install the JDK (or equivalent) in the compilation system
You will need to call the Java compiler
You will probably have to use compiled code using the Java Runtime (or equivalent)
Method A: The easiest way to use the compiler and use the compiled code is Process.Start , as stated in Cyrene's answer. This is easy if you have the necessary components.
//add this either atusing System.Diagnostics; static void CompileJava(string javacPathName, string javaFilePathName, string commandLineOptions = "") { var startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.FileName = javacPathName; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.Arguments = commandLineOptions + " " + javaFilePathName; try { using (var javacProcess = Process.Start(startInfo)) { javacProcess.WaitForExit(); } } catch(Exception e) { // do something eg throw a more appropriate exception } }
Method B: If you need deeper integration, you can try your own binding method (for example, use .NET and the native Java interfaces to interact between them without calling external processes). The prerequisites are the same as in Method A. The required investments are much higher, and you should only consider this if there are certain performance indicators or other limitations that Method A cannot fulfill.
You can find the information at the links below:
From C # side: http://blogs.msdn.com/b/texblog/archive/2007/04/05/linking-native-c-into-c-applications.aspx
From the Java side: http://docs.oracle.com/javase/6/docs/technotes/guides/jni/
source share