2014年8月6日 星期三

[研究] Apache Maven 3.2.2 (tar.gz)安裝 (CentOS 7.0 x64_86)

[研究] Apache Maven 3.2.2 (tar.gz)安裝 (CentOS 7.0 x64_86)

2014-08-06

介紹
http://maven.apache.org/ref/3.2.2/

Maven是一個專案的開發,管理和綜合工具。

下載
http://maven.apache.org/download.cgi

參考
http://maven.apache.org/download.cgi#Installation

使用教學
http://maven.apache.org/guides/getting-started/index.html
http://maven.apache.org/guides/index.html

Java JDK 請自己手動下載

安裝

#rpm -ivh jdk-7u45-linux-x64.rpm
yum -y install  java
yum -y install  java-1.7.0-openjdk-devel
#wget http://ftp.tc.edu.tw/pub/Apache/maven/maven-3/3.1.1/binaries/apache-maven-3.2.2-bin.tar.gz
wget http://apache.stu.edu.tw/maven/maven-3/3.2.2/binaries/apache-maven-3.2.2-bin.tar.gz
tar zxvf apache-maven-3.2.2-bin.tar.gz -C /usr/local
ln  -s  /usr/local/apache-maven-3.2.2/bin/mvn  /usr/bin/mvn

export M2_HOME=/usr/local/apache-maven-3.2.2
export M2=$M2_HOME/bin
# MAVEN_OPTS 非必須
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=$M2:$PATH

#export JAVA_HOME=/usr/java/jdk1.7.0_45
export JAVA_HOME=/usr

OpenJDK 的安裝目錄如下,因為 mvn 會執行 JAVA_HOME/bin/java 程式,而實際 java 程式在 /usr/bin/java,所以設定 JAVA_HOME=/usr,是否會有其他問題不知

[root@localhost ~]# find / -name java
find: ‘/run/user/1000/gvfs’: Permission denied
/etc/pki/ca-trust/extracted/java
/etc/pki/java
/etc/java
/etc/alternatives/java
/var/lib/alternatives/java
/usr/bin/java
/usr/lib/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre-abrt/bin/java
/usr/lib64/libreoffice/ure/share/java
/usr/lib64/libreoffice/share/Scripts/java
/usr/share/java
[root@localhost ~]#

測試

顯示版本

[root@localhost ~]# mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T21:51:42+08:00)
Maven home: /usr/local/apache-maven-3.2.2
Java version: 1.7.0_65, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-123.el7.x86_64", arch: "amd64", family: "unix"
[root@localhost ~]#

下載測試 (所有問題全部用 Enter 回應)

[root@localhost ~]# mvn archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DgroupId=com.mycompany.app \
  -DartifactId=my-app

...(略)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:52 min
[INFO] Finished at: 2014-08-06T22:09:37+08:00
[INFO] Final Memory: 16M/247M
[INFO] ------------------------------------------------------------------------
[root@localhost ~]#


編譯測試

[root@localhost ~]# cd  my-app

[root@localhost my-app]# mvn compile
...(略)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.097 s
[INFO] Finished at: 2014-08-06T22:10:53+08:00
[INFO] Final Memory: 9M/247M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project my-app: Fatal error compiling: tools.jar not found: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/../lib/tools.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[root@localhost my-app]#

發生錯誤,tools.jar 要安裝 OpenJDK 的 devel 套件才有

[root@localhost my-app]# yum -y install  java-1.7.0-openjdk-devel

[root@localhost my-app]# mvn compile
...(
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.041 s
[INFO] Finished at: 2014-08-06T22:15:55+08:00
[INFO] Final Memory: 12M/247M
[INFO] ------------------------------------------------------------------------
[root@localhost my-app]#


[root@localhost my-app]# mvn test
...(略)
Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.277 s
[INFO] Finished at: 2014-08-06T22:17:28+08:00
[INFO] Final Memory: 15M/247M
[INFO] ------------------------------------------------------------------------
[root@localhost my-app]#



[root@localhost my-app]#  mvn -help

usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -am,--also-make                        If project list is specified, also
                                        build projects required by the
                                        list
 -amd,--also-make-dependents            If project list is specified, also
                                        build projects that depend on
                                        projects on the list
 -B,--batch-mode                        Run in non-interactive (batch)
                                        mode
 -b,--builder <arg>                     The id of the build strategy to
                                        use.
 -C,--strict-checksums                  Fail the build if checksums don't
                                        match
 -c,--lax-checksums                     Warn if checksums don't match
 -cpu,--check-plugin-updates            Ineffective, only kept for
                                        backward compatibility
 -D,--define <arg>                      Define a system property
 -e,--errors                            Produce execution error messages
 -emp,--encrypt-master-password <arg>   Encrypt master security password
 -ep,--encrypt-password <arg>           Encrypt server password
 -f,--file <arg>                        Force the use of an alternate POM
                                        file (or directory with pom.xml).
 -fae,--fail-at-end                     Only fail the build afterwards;
                                        allow all non-impacted builds to
                                        continue
 -ff,--fail-fast                        Stop at first failure in
                                        reactorized builds
 -fn,--fail-never                       NEVER fail the build, regardless
                                        of project result
 -gs,--global-settings <arg>            Alternate path for the global
                                        settings file
 -h,--help                              Display help information
 -l,--log-file <arg>                    Log file to where all build output
                                        will go.
 -llr,--legacy-local-repository         Use Maven 2 Legacy Local
                                        Repository behaviour, ie no use of
                                        _remote.repositories. Can also be
                                        activated by using
                                        -Dmaven.legacyLocalRepo=true
 -N,--non-recursive                     Do not recurse into sub-projects
 -npr,--no-plugin-registry              Ineffective, only kept for
                                        backward compatibility
 -npu,--no-plugin-updates               Ineffective, only kept for
                                        backward compatibility
 -nsu,--no-snapshot-updates             Suppress SNAPSHOT updates
 -o,--offline                           Work offline
 -P,--activate-profiles <arg>           Comma-delimited list of profiles
                                        to activate
 -pl,--projects <arg>                   Comma-delimited list of specified
                                        reactor projects to build instead
                                        of all projects. A project can be
                                        specified by [groupId]:artifactId
                                        or by its relative path.
 -q,--quiet                             Quiet output - only show errors
 -rf,--resume-from <arg>                Resume reactor from specified
                                        project
 -s,--settings <arg>                    Alternate path for the user
                                        settings file
 -T,--threads <arg>                     Thread count, for instance 2.0C
                                        where C is core multiplied
 -t,--toolchains <arg>                  Alternate path for the user
                                        toolchains file
 -U,--update-snapshots                  Forces a check for missing
                                        releases and updated snapshots on
                                        remote repositories
 -up,--update-plugins                   Ineffective, only kept for
                                        backward compatibility
 -V,--show-version                      Display version information
                                        WITHOUT stopping build
 -v,--version                           Display version information
 -X,--debug                             Produce execution debug output
[root@localhost my-app]#


其他使用教學請看
http://maven.apache.org/guides/getting-started/index.html
http://maven.apache.org/guides/index.html

(完)

[研究] Apache Maven 3.2.2 (tar.gz)安裝 (CentOS 7.0 x64_86)
http://shaurong.blogspot.com/2014/08/apache-maven-322-targz-centos-70-x6486.html

[研究] Apache Maven 3.0.5 (yum) 安裝 (CentOS 7.0 x64_86)
http://shaurong.blogspot.com/2014/08/apache-maven-305-yum-centos-70-x6486.html

[研究] Apache Maven 3.1.1 安裝 (CentOS 6.4 x64)
http://shaurong.blogspot.com/2013/11/apache-maven-311-centos-64-x64.html
http://forum.icst.org.tw/phpbb/viewtopic.php?t=80036

[研究] Apache Maven 3.0.3 (yum) 安裝 (CentOS 6.4 x64)
http://shaurong.blogspot.tw/2013/11/apache-maven-303-yum-centos-64-x64.html


沒有留言:

張貼留言