Running Maven from Java code in Windows?

2012-03-13T04:21:23

I am trying to run maven from my java class based on this suggestion:

How to run maven from java?

Runtime.getRuntime().exec("mvn");

but I get:

java.io.IOException: Cannot run program "mvn": CreateProcess error=2, The system cannot find the file specified

mvn is on my path and I can run it just fine from cmd:

C:\Users\m>mvn -v
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\apache-maven-3.0.3\bin\..
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_20\jre
...

any suggestions?

Copyright License:
Author:「u123」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/9674220/running-maven-from-java-code-in-windows

About “Running Maven from Java code in Windows?” questions

I am trying to run maven from my java class based on this suggestion: How to run maven from java? Runtime.getRuntime().exec("mvn"); but I get: java.io.IOException: Cannot run program "mvn":
I know that maven uses JAVA_HOME environment variable to start itself. But I cannot change that variable due to lack of administration priviligies (security policy in company). I have Oracle JRE
Summary: How to run an Eclipse Java Maven Project outside of Eclipse Details: I am a Maven newbie and I have created a very simple Maven project in Eclipse. The Package Explorer view of my p...
New to Java and Maven here. I am having problems successfully running mvn install on my Windows setup on JDK 16. The process always fails the verification step. The fail-safe folder from Maven show...
I'm attempting to compile javabot on windows using maven 2. I've compiled java programs in the past ( so I know the default JDK is working correctly), and this is my first time using maven. The err...
In my work I use an older version of Maven (3.0.2) to build my Java 1.7 application. This cannot be changed. But I would like to install and use for other projects on same computer (Windows) newer
This is probably the most strange thing I have ever seen in Java: The following code (that uses no external libraries) runs flawlessly using Ant (on Netbeans, on a Windows-7 Machine) : public static
I am running a windows desktop app programmed in java. The project also uses maven. I cloned the project from a bitbucket repository on my centos 7 os. I am absolutely sure that the project didn't ...
I am trying to build a project to checkout code from SCM and build it using maven. Is there a way we can achieve running maven goals from java without a maven home being provided(no maven installat...
The Windows 10 system environment variables JAVA_HOME and PATH are pointing to JDK 18 which is needed to launch VS Code and needed by other applications on the laptop. I configured Maven Project in...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.