Hello,

 

I have a call to a Java program that works on the windows7 command line:

d:\temp\test>"c:\progam files\java\java1.6\bin\java.exe" -cp subdir\main.jar package.of.MyMainClass

 

I need to execute this from another Java CLI application.

When calling the other App I am in the same working directory. This other application has its starter jar in the working dir and other jars in the same subdir. My Code is in a jar file in this subdir included in the starter apps classpath.

 

my code is:

ProcessBuilder processBuilder = new ProcessBuilder(Arrays.asList(
   "c:\progam files\java\java1.6\bin\java.exe",
  "-cp",
  "subdir\\main.jar",
  "package.of.MyMainClass"
));
 processBuilder.directory(new File(".").getAbsoluteFile().getParentFile());
Process process = processBuilder.start();
System.out.println(process.waitFor());

 

where

new File(".").getAbsoluteFile().getParentFile()

resoves to the working dir.

 

I get This error:

---------------------------

Java Virtual Machine Launcher

---------------------------

Could not find the main class: de.contiteves.application.ParameterGuiStart.  Program will exit.

---------------------------

OK  

---------------------------

 

Why does my program run from the command line directly but  not when executed byProcessBuilder?

 

bye

TPD

FacebookTwitterLinkedin
Pin It
Joomla Tutorials for Beginners