简体   繁体   中英

Running Maven Command From Java Program (From Eclipse) Mac OS

I want to run Maven command from Java in Mac but I am getting the following error:

Exception in thread "main" java.io.IOException: Cannot run program "mvn": error=2, No such file or directory

My code looks like this:

p = Runtime.getRuntime().exec("mvn -version");

If I run the following command, it works fine. The only issue is related to Maven:

p = Runtime.getRuntime().exec("ls -ltr");

Does mvn -version works within the terminal window in eclipse? i had an issue running mvn command on eclipse terminal while it was working in OS terminal. I found these steps that fixed my issue:

  1. add the "mvn_installation_location"/bin to /etc/paths file as root user.
  2. right click eclipse and "show contents" then run eclipse from /Contents/MacOS/eclipse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM