3

I am attempting to run an xcode project which has a simply build phase script that executes mvn install. When I try to build, I receive the error mvn command not found. However, if I run mvn -v on the terminal mvn works. As well, other IDE's which I use (such as Android Studio and Eclipse) have picked up on my maven installation.

This leads me to believe that perhaps the build phase scripts are not executing as my user. However, I cannot find any reference as to what user the build phase scripts will use, or if the user is configurable.

Why is Xcode not picking up on mvn which is on my user's path?

UPDATE:

When I do whoami I see that the script is running in xcode as my user which makes this all the more confusing for me.

Also, thanks to the suggestion by I'L'I I was able to discover that using the fully qualified path would work. I am not really sure why this is the case because

stevebot
  • 23,275
  • 29
  • 119
  • 181
  • Note there is a similar question here: http://stackoverflow.com/questions/27436437/xcode-mvn-no-such-file-or-directory/27450341#27450341 which has no satisfactory answer. – stevebot Mar 04 '15 at 17:11
  • It might be a permissions issue; maybe. What happens if you put `sudo` in front of the build script command? Or how about using the absolute path? – l'L'l Mar 04 '15 at 17:20
  • How would it be a permissions issue? I also don't get how the absolute path would make a difference? – stevebot Mar 04 '15 at 17:24
  • `"This leads me to believe that perhaps the build phase scripts are not executing as my user. "` — that's how (re: permissions issue). And it's possible XCode isn't finding the path to the mvn executable, so that's why the absolute path may help. – l'L'l Mar 04 '15 at 17:27
  • 1
    Yes, you are correct, if I use the fully qualified path it works. However, I find it strange that whoami returns my current user. – stevebot Mar 04 '15 at 18:33

1 Answers1

1

Giving the full path of your mvn installation(/localpath/bin/mvn) might solve the issue but It may have some limitations.

You may not want to give your full path path for mvn(which may have a local path) and checkin your project file to a repo. All users who checkout your project has to edit the project file to point mvn to their local installation.

Xcode apparently picks mvn from /usr/bin directory if we do not specify the full path . So if we can provide a soft link from the local installation to /usr/bin/mvn , Xcode will pick the mvn even without specifying the full path of the mvn.

command to make a soft link : sudo ln -sf /Users/chandu/apache-maven-3.3.9/bin/mvn /usr/bin/mvn

verify that link is established with the below command: chandras-MacBook-Pro:~ chandu$ ls -al /usr/bin/mvn lrwxr-xr-x 1 root wheel 40 May 18 15:14 /usr/bin/mvn -> /Users/chandu/apache-maven-3.3.9/bin/mvn

Apple has disabled soft linking on OSX EL Capitan. To soft link on OSX EL Capitan , login in recovery mode and run csrutil disable and then login back in normal mode and try establishing soft link . Also make sure you enable SIP by logging in recovery mode and running csrutil enable

You can also try linking to /usr/local/bin/mvn to avoid the above step in OSX EL Capitan.Xcode seem to pick up binaries from /usr/local/bin path too.

Chandra
  • 379
  • 3
  • 13