3

I am running a Java batch file from C#. If I run it by double clicking it executes successfully, but if I run it from C# code it gives exception in thread

"exception in "main" thread java.lang.noclassdeffoundError"..

what can be the reason and how can it be solved? I am using the code:

var si = new ProcessStartInfo();

si.CreateNoWindow = true;
si.FileName = "batch-file path";
si.UseShellExecute = true;

Process.Start(si);
forsvarir
  • 10,749
  • 6
  • 46
  • 77
mucchar
  • 111
  • 1
  • 1
  • 2

4 Answers4

1

You are most likely missing some of the parameters that would be included in your systems environment variables.

Nick Berardi
  • 54,393
  • 15
  • 113
  • 135
  • I really can't because I don't know anything about the Java program you are trying to run. But this other OS article might help you get started: http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java – Nick Berardi May 12 '11 at 13:41
0

Try setting working directory like this

process.StartInfo.WorkingDirectory = "C:\";

Also, try few other options as mentioned here,

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/20992653-dabf-4b31-85f7-e7bfbfb4557c

Priyank
  • 10,503
  • 2
  • 27
  • 25
0

Try adding the following code as the first line to your batch file.

@cd /d %~dp0
AbrahamJP
  • 3,425
  • 7
  • 30
  • 39
0

Do not use batch_process_path + "\" + instead use Path.Combine() to make sure the path is correctly fitted with slashes.

Also read this "When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable"

So set it to false.

Emond
  • 50,210
  • 11
  • 84
  • 115