0

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

1 Answer 1

2

Try this instead;

Process pr = rt.exec("cmd /c mvn liquibase:update");
answered Apr 21, 2021 at 20:49
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.