我需要在家里的Mac的环境把私有jar包添加到本地maven仓库。首先我使用brew安装maven:
$ brew install maven
...
maven-3.3.3 already installed.
本以为安装了maven命令行就可以。远远没有那么easy,运行mvn命令就提示下面的报错信息。
Problem #1
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
根据保存信息中不被支持的class版本,可以判断出来是jdk版本的问题导致的,查看了maven3.3.3的依赖,发现maven编译时候使用的是jdk7.Mac本来安装的是Apple官方提供的jdk6,去安装jdk7吧,皮卡丘!
Oracle官网去下载jdk7 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
安装之后,要在当前用户的配置下面修改环境变量,以支持命令行运行环境为jdk7.
The Solution
$ vi ~/.bash_profile
#java Env
JAVA_HOME=`/usr/libexec/java_home -v 1.7`
#MAVEN Env
M2=`brew --prefix maven`/libexec/bin
M2_HOME=`brew --prefix maven`/libexec
#PATH
PATH=$JAVA_HOME/bin:$M2:$PATH
export JAVA_HOME
export M2
export M2_HOME
export PATH
$ source ~/.bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
$ mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19:57:37+08:00)
Maven home: /usr/local/opt/maven/libexec
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"
maven 妥妥地安装好了!
Problem #2
下一步就是把本地的jar,添加到本地仓库里咯:以安装银联的jar包*upacp_sdk-1.0.1.jar*为例,此jar放在本地的/Users/USER_NAME/work/local_repo/upacp_sdk-1.0.1.jar
中,groupId是com.unionpay.acp.sdk,artifactId是upacp_sdk
,版本version是1.0.1
,要安装到本地仓库里。
The Solution
下面是命令行执行情况:
$ mvn install:install-file -Dfile=/Users/USER_NAME/work/local_repo/upacp_sdk-1.0.1.jar -DgroupId=com.unionpay.acp.sdk -DartifactId=upacp_sdk -Dversion=1.0.1 -Dpackaging=jar;
安装成功。