Linux下安装maven
1.首先到Maven官网下载安装文件,目前最新版本为3.0.3,下载文件为apache-maven-3.0.3-bin.tar.gz,下载可以使用wget命令;
2.进入下载文件夹,找到下载的文件,运行如下命令解压
tar -xvf apache-maven-2.2.1-bin.tar.gz
解压后的文件夹名为apache-maven-3.0.3
3.使用mv命令将apache-maven-3.0.3文件夹拷贝到自己指定的文件夹,比如/usr/local/下
mv -rf apache-maven-3.0.3 /usr/local/
4.配置环境变量,编辑/etc/profile文件,添加如下代码
export MAVEN_HOME=/usr/local/apache-maven-3.0.3
export PATH=${PATH}:${MAVEN_HOME}/bin
5.保存文件,并运行如下命令使环境变量生效
source /etc/profile
6.在控制台输入如下命令,如果能看到Maven相关版本信息,则说明Maven已经安装成功
mvn -version
Linux中搭建本地仓库
1. 下载nexus
下载最新版nexus(到目前为止最新版为nexus-2.7.0-05,下载地址http://www.sonatype.org/nexus/go,得到nexus-latest-bundle.tar.gz
2. 下载完成后将nexus-latest-bundle.tar.gz拷贝到/usr/local/目录下,并进入/usr/local目录
sudo cp nexus-latest-bundle.tar.gz /usr/local/
cd /usr/local
3. 解压nexus-latest-bundle.tar.gz,得到nexus-2.7.0-05和sonatype-work,并做一个软链接
tar -zxvf nexus-latest-bundle.tar.gz
4.运行nexus
./bin/nexus start
5、测试
在浏览器中访问:localhost:8081/nexus ,输入用户名与密码(默认的admin、admin123)就可以管理自己的maven本地仓库了
如果安装成功但在浏览器中访问不了(访问默认地址:http://localhost:8081/nexus),通过查看wrapper.log日志可能会看到“Unable to start java JVM:No such file or directory",
此时需要将wrapper.conf文件里面的wapper.java.command=java修改成wapper.java.command=%JAVA_HOME%/bin/java(就是安装jdk所在的文件路径);
下面说下我在安装后启动时遇到的问题:
1. Unable to start java JVM:No such file or directory,解决方法,修改wapper.conf配置文件里面的wapper.java.command。我开始修改成wapper.java.command={JAVA_HOME}/bin/java,但根本不起作用,看网上很我资料也说是改成那样,最后无意中看到一篇文章(具体是哪篇忘记了)说是改wapper.java.command=%JAVA_HOME%/bin/java,要用%%而不是用{}。
2.还有一个问题就是启动时报如下异常
/usr/local/nexus$ ./bin/nexus console
Running Nexus OSS...
wrapper | --> Wrapper Started as Console
wrapper | Launching a JVM...
jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
jvm 1 |
jvm 1 | 2013-12-31 20:07:56 INFO [WrapperListener_start_runner] - org.sonatype.nexus.bootstrap.jsw.JswLauncher - Starting with arguments: [./conf/jetty.xml]
jvm 1 | 2013-12-31 20:07:56 INFO [WrapperListener_start_runner] - org.sonatype.nexus.bootstrap.jsw.JswLauncher - JVM ID: 1, JVM PID: 2594, Wrapper PID: 2592, User: linming
jvm 1 | 2013-12-31 20:07:56 INFO [WrapperListener_start_runner] - org.sonatype.nexus.bootstrap.jsw.JswLauncher - Current directory: /usr/local/nexus-2.7.0-05
jvm 1 | 2013-12-31 20:07:57 INFO [WrapperListener_start_runner] - org.sonatype.nexus.bootstrap.jsw.JswLauncher - Temp directory: /usr/local/sonatype-work/nexus/tmp
jvm 1 | 2013-12-31 20:07:57 ERROR [WrapperListener_start_runner] - org.sonatype.nexus.bootstrap.jsw.JswLauncher - Failed to start
jvm 1 | java.nio.file.AccessDeniedException: /usr/local/sonatype-work/nexus/tmp
jvm 1 | at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[na:1.7.0_07]
jvm 1 | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[na:1.7.0_07]
jvm 1 | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[na:1.7.0_07]
jvm 1 | at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:382) ~[na:1.7.0_07]
jvm 1 | at java.nio.file.Files.createDirectory(Files.java:628) ~[na:1.7.0_07]
jvm 1 | at java.nio.file.Files.createAndCheckIsDirectory(Files.java:732) ~[na:1.7.0_07]
jvm 1 | at java.nio.file.Files.createDirectories(Files.java:718) ~[na:1.7.0_07]
jvm 1 | at org.sonatype.nexus.bootstrap.Launcher.ensureTmpDirSanity(Launcher.java:247) ~[nexus-bootstrap-2.7.0-05.jar:2.7.0-05]
jvm 1 | at org.sonatype.nexus.bootstrap.Launcher.start(Launcher.java:95) ~[nexus-bootstrap-2.7.0-05.jar:2.7.0-05]
解决方法:
sudo chmod -R 777 sonatype-work/nexus
3、报错
****************************************
WARNING – NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
大概意思就是要在环境配置export RUN_AS_USER=root,临时配置
在命令行下输入:
export RUN_AS_USER=root
然后执行,就不会再提示了
./nexus start