Executing Java Object in C#
-
I have this task, i need to call a Java Application using a web-service call.I need to know if someone has a clue on how to do that,so far this is my attempt.
string cmd ="C:\Program Files\Java\jre1.6.0\bin\Java.exe";
//We use this command to invoke or start the java application which take argument infront.string cmdParams="java -Xms32m -Xmx1g -Djava.library.path=d:\cep\col\sql -classpath d:\cep\col\commons-net-1.4.1.jar;d:\cep\col\commons-codec-1.3.jar;d:\cep\col\sql\sqljdbc.jar;d:\cep\col\DialogInput.jar za.co.lightWave.control.DialogInputControl";
using (Process process = Process.Start(new ProcessStartInfo(cmd, cmdParams)))
{process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError= true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(timeout); return process.ExitCode; }
I need to know what is an effective way of executing that command,what i have currently is
java.lang.NoClassDefFoundError: java Exception in thread "main"
Thank you in advance Mninawa
-
I have this task, i need to call a Java Application using a web-service call.I need to know if someone has a clue on how to do that,so far this is my attempt.
string cmd ="C:\Program Files\Java\jre1.6.0\bin\Java.exe";
//We use this command to invoke or start the java application which take argument infront.string cmdParams="java -Xms32m -Xmx1g -Djava.library.path=d:\cep\col\sql -classpath d:\cep\col\commons-net-1.4.1.jar;d:\cep\col\commons-codec-1.3.jar;d:\cep\col\sql\sqljdbc.jar;d:\cep\col\DialogInput.jar za.co.lightWave.control.DialogInputControl";
using (Process process = Process.Start(new ProcessStartInfo(cmd, cmdParams)))
{process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError= true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(timeout); return process.ExitCode; }
I need to know what is an effective way of executing that command,what i have currently is
java.lang.NoClassDefFoundError: java Exception in thread "main"
Thank you in advance Mninawa
Hi, Have you tried running the command you are attempting to run in the command line first to make sure that the command actually works? What you are getting is an error from Java that says it cannot find a certain class. This is almost always a problem with the classpath argument of the command. Try debugging the command in cmd.exe first and then once you are sure the command works, try doing it in code. Steve
-
Hi, Have you tried running the command you are attempting to run in the command line first to make sure that the command actually works? What you are getting is an error from Java that says it cannot find a certain class. This is almost always a problem with the classpath argument of the command. Try debugging the command in cmd.exe first and then once you are sure the command works, try doing it in code. Steve
PS. I just had a closer look at your commands. You are setting the command to call the Java virtual machine (Java.exe) which is fine. But you are then setting the first argument (in your cmdParams) to "java" then "-xms32m...etc". Did you mean to put jar instead of java? When you execute a JAR file on the command line it should be something like "C:\whatever\Java.exe -jar MyJar.jar". Take a look at the documentation for the Java Virtual Machine when running JAR files. Steve
-
PS. I just had a closer look at your commands. You are setting the command to call the Java virtual machine (Java.exe) which is fine. But you are then setting the first argument (in your cmdParams) to "java" then "-xms32m...etc". Did you mean to put jar instead of java? When you execute a JAR file on the command line it should be something like "C:\whatever\Java.exe -jar MyJar.jar". Take a look at the documentation for the Java Virtual Machine when running JAR files. Steve
Hi Steve,thanx for your help. On that not you are quite right,In the documentations for JVM,this is how you would execute .jar file,but now what i have is the combination of libraries,which makes up an application caller,which is that cmdParam, well i have to find a way to execute them in C# and I thought using this way would solve the problem. I thought one might have a solution besides the one in did,because i have to do them that way. Mninawa
-
I have this task, i need to call a Java Application using a web-service call.I need to know if someone has a clue on how to do that,so far this is my attempt.
string cmd ="C:\Program Files\Java\jre1.6.0\bin\Java.exe";
//We use this command to invoke or start the java application which take argument infront.string cmdParams="java -Xms32m -Xmx1g -Djava.library.path=d:\cep\col\sql -classpath d:\cep\col\commons-net-1.4.1.jar;d:\cep\col\commons-codec-1.3.jar;d:\cep\col\sql\sqljdbc.jar;d:\cep\col\DialogInput.jar za.co.lightWave.control.DialogInputControl";
using (Process process = Process.Start(new ProcessStartInfo(cmd, cmdParams)))
{process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError= true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(timeout); return process.ExitCode; }
I need to know what is an effective way of executing that command,what i have currently is
java.lang.NoClassDefFoundError: java Exception in thread "main"
Thank you in advance Mninawa
Hi, 1. to execute a java class, you should issue the command "java [options] classname" which means "java" is the command, and everything else is in the arguments. So I would remove the "java " from cmdParams (I guess you already did that). 2. Furthermore, in Java there is a direct link between composite class names (as in your "za.co.lightWave.control.DialogInputControl") and your file hierarchy. So your classpath (either the enviroment variable or the options you specify) must lead to the location that is holding za\co\lightWave\control\DialogInputControl.class java.lang.NoClassDefFoundError is the error you would get when not satisfying this requirement. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.