tags:

views:

257

answers:

3

I have a c# program that access a java program by tcp. In my C# program I'm starting the java program by this line of code:

var process = new Process
{
  StartInfo =
  {
      UseShellExecute = false,
      CreateNoWindow = false,
      FileName = "cmd.exe",
      Arguments = (@"/c java -ms16m -mx512m -jar pathToJavaApp/javaApp.jar 3562")
  }
};

This works fine I had no problems until now. I've installed my program on a colleague's computer. Now I'm getting the error: Unable to access the jar file.

So I tried in command line "java -jar javaApp.jar" and the javaApp starts immediately.

I tried starting the program as administrator, same error. (windows vista)

For the moment I have no idea what the problem could be.

+1  A: 

My guess is that the path to the jar file contains spaces. You'll need to quote it. For example:

Arguments = "/c java -ms16m -mx512m -jar \"" + pathToJavaApp 
    + "\"/javaApp.jar 3562"
Jon Skeet
var pathJava = Application.StartupPath + "\\pathToJavaApp\\javaApp.jar";this is how my path is created before passing it to the process
Gerbrand
maybe it is int he application.startuppath that contains spaces
Gerbrand
Like you said there are some spaces in the path. the spaces are like I thought in the Application.StartupPath.
Gerbrand
A: 

2 things-

  • it's -Xmx, and -Xms, not -ms, -mx.

  • Does your program load any additional jars? maybe they exist on your colleagues computer but not on the one it wouldn't run on.

(although Jon Skeet's answer looks more likely)

Steve B.
A: 

In order to see more about what is going on change your arguments to:

  Arguments = (@"/c java -verbose -ms16m -mx512m -jar pathToJavaApp/javaApp.jar 3562")

That way you can see what it is trying to load and see if Jon Skeet is correct.

James Black