How to Execute a Java Program from C#

How to execute a Java program from C#?

If you need finer control than launching an external program, then consider IKVM - http://www.ikvm.net/ - which provides a way to run Java programs inside a .NET world.

What are some ways to compile Java from C# code?

You do have other options. Java provides JNI (Java Native Interface ) which allows Java to call native code and apropos, for native code to call Java (albeit in a rather complex way.)

Depending on how much of a learning experience you want this to be you can use JNI directly or use a library such as jni4net. A different interop approach is to use ikvm which is a jvm running inside the clr, but I don't think it'll be useful to you as it does not include a compiler.

You can also research alternative compilers such as gcj or ejc.

Not having tried to write an IDE I don't know whether these approaches are actually better than using the command line directly. My hunch is that for simple integration the command line is the easier to use however more complex scenarios, e.g. incremental compilation of large projects with multiple components, may require tighter integration.

If you plan on providing features such as inline debugging and error highlighting while you type you're going to require tighter integration anyway.

IDEs are extremely complex programs, even mere programming editors are complex enough.

How to execute a Java app with arguments in c#

You need to put spaces in the strings you're concatenating, your command currently looks like

java -jar javaapp.jarhost:portpassword/saytest

The simplest way is to use string.Format:

string command1 = "/say"
string command2 = "test"
string args = string.Format("-jar javaapp.jar {0}:{1} {2} {3} {4}", host, port, password, command1, command2);
startInfo.Arguments = args;

Running Java Application in C# NET

If you launch and manage the java app from C# using the Process class, you can send input from your C# app to the launched java app process via Process.StandardInput.

How to run jar file form C# code

You will have to provide -jar switch to java command.

For example, the command to execute JAR file is,

java -jar D:\\DATA\\PROJECT\\LicensingManagement\\Assignment\\JavaLogin.jar

So you may try,

myProcess.StartInfo.Arguments = "-jar D:\\DATA\\PROJECT\\LicensingManagement\\Assignment\\JavaLogin.jar";


Related Topics



Leave a reply



Submit