0

In my project, Tomcat is deploying a WAR file. The WAR file is trying to run maven on another project:

List<String> args = new ArrayList<String>();
args.add("mvn");
for (String goal : goals) {
    args.add(goal);         
    //Here, goals is { "clean", "compile", "test", "dependency:copy-dependencies" }
}

ProcessBuilder processBuilder = new ProcessBuilder(args).directory(workingDir);
processBuilder.redirectErrorStream();
Process process = processBuilder.start();

However, tomcat cannot run maven and is giving this error:

java.io.IOException: Cannot run program "mvn" (in directory "C:/..."): CreateProcess error=2, The system cannot find the file specified

I'm new to Tomcat and Maven, but I'm pretty sure I have JAVA_HOME, CATALINA_HOME, MAVEN_HOME all set up correctly to their bin folders, and added to PATH as well. I'm not using any IDE, just using cmd and browser.

Is there some kind of configuration in Tomcat which does not allow it to run external processes? Can that be changed?

Thanks for the help!

amrita
  • 133
  • 2
  • 13

1 Answers1

0

I think it is likely that mvn is not a command which can be run and your process should be cmd \c mvn which essentially tells Java to launch a command terminal and instructs the command terminal to run maven.

For portability reasons, you should see this question: How to run maven from java?

By using a portable API you can gain platform independence and leave out the clunky sub-process handling.

Community
  • 1
  • 1
Tim Bender
  • 20,112
  • 2
  • 49
  • 58
  • cmd \c mvn is giving same error. But if I tried any of the approaches mentioned in that question, how would I specify workingDir? – amrita Sep 29 '15 at 08:09