我正在尝试按照这些说明通过终端安装maven。
到目前为止我得到了这个:
export M2_HOME=/user/apple/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/usr/java/jdk1.6.0_22
你去哪儿找这个?
我正在尝试按照这些说明通过终端安装maven。
到目前为止我得到了这个:
export M2_HOME=/user/apple/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/usr/java/jdk1.6.0_22
你去哪儿找这个?
当前回答
在使用brew或手动安装maven后,使用macOS Catalina并使用终端或iTerm来操作maven,您将需要授予应用程序访问权限以访问用户文件。
系统首选项->隐私(按钮)->全磁盘访问
然后将terminal或iTerm添加到该列表中。
你还需要重新启动你的应用程序,例如终端或iTerm,在给他们完全的磁盘访问权限后。
其他回答
这个命令酿造安装maven30不适合我。正在抱怨缺少配方。但是下面的命令起作用了。我已经安装了maven-3.0.5。
brew install homebrew/versions/maven30
这是Mac OS X 10.9又名Mavericks。
对于那些刚刚迁移到mavericks的-我使用*-ux解决方案;
从apache maven站点下载maven 输入/opt 修改了.bash_profile,新增: 别名mvn = ' / opt / apache-maven-3.1.1 / bin / mvn ' 出口JAVA_HOME = /图书馆/ Java / Home / JavaVirtualMachines / jdk1.7.0_21.jdk /内容
两个方法
(use homebrew) Auto install: Command: brew install maven Pros and cons Pros: easy Cons: (probably) not latest version Manually install (for latest version): Pros and cons Pros: use your expected any (or latest) version Cons: need self to do it Steps download latest binary (apache-maven-3.6.3-bin.zip) version from Maven offical download uncompress it (apache-maven-3.6.3-bin.zip) and added maven path into environment variable PATH normally is edit and add: export PATH=/path_to_your_maven/apache-maven-3.6.3/bin:$PATH into your startup script( ~/.bashrc or ~/.zshrc etc.)
额外的注意
如何立即生效并检查安装是否正确?
A:
source ~/.bashrc
echo $PATH
which mvn
mvn --version
这里的输出:
➜ bin pwd
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin
➜ bin ll
total 64
-rw-r--r--@ 1 crifan staff 228B 11 7 12:32 m2.conf
-rwxr-xr-x@ 1 crifan staff 5.6K 11 7 12:32 mvn
-rw-r--r--@ 1 crifan staff 6.2K 11 7 12:32 mvn.cmd
-rwxr-xr-x@ 1 crifan staff 1.5K 11 7 12:32 mvnDebug
-rw-r--r--@ 1 crifan staff 1.6K 11 7 12:32 mvnDebug.cmd
-rwxr-xr-x@ 1 crifan staff 1.5K 11 7 12:32 mvnyjp
➜ bin vi ~/.bashrc
➜ bin source ~/.bashrc
➜ ~ echo $PATH
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin:xxx
➜ bin which mvn
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin/mvn
➜ bin mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3
Java version: 1.8.0_112, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
详情请参考我的(中文)帖子:【已解决】Mac中安装Gradle
当我最近升级到OS X Mavericks时,我的maven构建开始失败。所以我需要再次安装maven,因为它不是内置的。然后我试着输入命令:
brew install maven
它可以工作,但它安装了maven的3.1.1版本,这对一些用户(https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound)造成了一些问题。因此,如果遇到同样的问题,您可能希望安装较早的Maven版本3.0.5。要在Homebrew中做到这一点,你必须执行以下命令:
brew install https://raw.github.com/Homebrew/homebrew-versions/master/maven30.rb
就是这样,它将使用不同的Homebrew公式,这将为您提供maven 3.0.5。
在OS X上安装Maven,请到Apache Maven官网下载二进制压缩文件。
然后,您可以将下载文件夹中的apache-maven-3.0.5文件夹转移到您想要保存Maven的任何地方;然而,由于其余的过程涉及到命令行,我建议你从那里做所有的事情。
在命令行中,你可以运行如下代码:
mv ~/Downloads/apache-maven-3.0.5 ~/Development/
这只是我个人的偏好——在我的主目录中有一个“Development”目录。如果你愿意,你可以选择其他的。
接下来,编辑~/。在您选择的编辑器中配置文件,并添加以下内容:
export M2_HOME="/Users/johndoe/Development/apache-maven-3.0.5"
export PATH=${PATH}:${M2_HOME}/bin
第一行对Maven很重要(必须是一个完整的显式路径);为了运行“mvn”二进制文件,第二行对shell很重要。如果.profile中已经有第二行的变体,那么只需在它的末尾添加${M2_HOME}/bin。
现在打开第二个终端窗口并运行
mvn -version
输出应该是这样的…
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 13:51:28+0000)
Maven home: /Users/johndoe/Development/apache-maven-3.0.5
Java version: 1.7.0_40, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
有几件事需要注意:
If you've installed the Oracle JDK 1.7, then you may find Maven reports JDK 1.6 in the above output. To solve this, add the following to your ~/.profile: export JAVA_HOME=$(/usr/libexec/java_home) As some have pointed out, Maven has historically been supplied either with OS X itself, or with the optional Command Line Tools for XCode. This may cease to be the case for future versions of OS X, and in fact OS X Mavericks does not include Maven. Personal opinion: This could be because they are still in beta, or it could be that Apple have taken a look at the latest Thoughtworks Technology Radar, and spotted that Maven has been moved to "Hold".