2

i just tried to execute mvn from an ant task vor the first time. It doesn't work.

I tried to fix this problem by this .profile file in ~:

export JAVA_HOME=$(/usr/libexec/java_home)
export M2_HOME=/usr/local/Cellar/maven/3.2.3/

PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH

but still i get this error:

BUILD FAILED /.../build.xml:13: Execute failed: java.io.IOException: Cannot run program "mvn": error=2, No such file or directory

i can run java and maven from the terminal, mvn --version:

Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4;
2014-08-11T22:58:10+02:00) Maven home:
/usr/local/Cellar/maven/3.2.3/libexec Java version: 1.8.0_25, vendor:
Oracle Corporation Java home:
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: de_DE, platform encoding: UTF-8 OS name: "mac os x",
version: "10.9.5", arch: "x86_64", family: "mac"
------------
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
------------
echo $M2_HOME
/usr/local/Cellar/maven/3.2.3/
Patrick Werner
  • 1,106
  • 9
  • 24
  • How are you running `mvn` in the Ant file? – M A Dec 10 '14 at 20:02
  • `.profile` is sourced only when you login. Have you tried logging out and logging in after you performed the modifications? Alternatively try this command to source the file manually `. ~/.profile` – Bohuslav Burghardt Dec 10 '14 at 20:02
  • In OSX .profile and other files are read on shell starts. GUI applications are not called via the shell and so they cannot be affected by what is in .profile - see many questions re setting environment variables in OS X – mmmmmm Dec 10 '14 at 20:05
  • Go through [this](http://stackoverflow.com/questions/7581156/how-to-call-for-a-maven-goal-within-an-ant-script) – pietv8x Dec 10 '14 at 20:05

1 Answers1

1

[first deprecated answer] I was finally able to fix my problem:

  • Uninstall maven: brew uninstall maven
  • Install maven again: brew install maven
  • add export JAVA_HOME=$(/usr/libexec/java_home) to ~/.profile

Now everything works like expected. [/first deprecated answer]

edit: this only fixed running maven on the console, you can workaround around this issue by starting Eclipse from the commandline.

For fixing the issue without the use of the terminal see this thread: Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?

Community
  • 1
  • 1
Patrick Werner
  • 1,106
  • 9
  • 24
  • 1
    Another thing you could consider is to use the [maven ant tasks](http://maven.apache.org/ant-tasks/) instead of calling mvn as an external process. This runs the maven build in the same JVM as ant and does not require maven to be installed at all (the ant tasks fetch their required libraries from the central repo). – Ian Roberts Feb 26 '15 at 10:20
  • thx for the comment, normally i would use maven ant tasks as well. The problem occured with a project wich was developed externally – Patrick Werner Feb 26 '15 at 13:47
  • Someone found the solution? I see "mvn install: No such file or directory" but the mvn commands works perfectly on the terminal... ( I installed mvn by brew) – Terranology Jun 06 '16 at 16:14