I want to run the command mvn liquibase:update if the user of the application sends the word run as command. How can I do it?
I already tried the following
if (args[0].equals("run")) {
Runtime rt = Runtime.getRuntime();
try {
Process pr = rt.exec("mvn liquibase:update");
} catch (IOException e) {
e.printStackTrace();
}
but I get the following error
ava.io.IOException: Cannot run program "mvn": CreateProcess error=2, O sistema não conseguiu localizar o ficheiro especificado
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1142)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
at java.base/java.lang.Runtime.exec(Runtime.java:591)
at java.base/java.lang.Runtime.exec(Runtime.java:415)
at java.base/java.lang.Runtime.exec(Runtime.java:312)
at com.petapilot.migrations.MigrationsApplication.main(MigrationsApplication.java:25)
Caused by: java.io.IOException: CreateProcess error=2, O sistema não conseguiu localizar o ficheiro especificado
at java.base/java.lang.ProcessImpl.create(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:483)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:158)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1109)
... 5 more
asked Apr 21, 2021 at 20:26
Fabio
3931 gold badge7 silver badges21 bronze badges
1 Answer 1
Try this instead;
Process pr = rt.exec("cmd /c mvn liquibase:update");
Sign up to request clarification or add additional context in comments.
1 Comment
Fabio
it worked but the only provided feedback is "Process finished with code 0". Is it possible to present the output of that command if runned in the console?
lang-java