移动WEB开发程序员

Mac下搭建Eclipse的maven开发环境

2015-12-30  本文已影响32595人  dzgdp888
系统版本:Mac OSX 10.11.2
Eclipse:Kepler Service Release 2
Maven:3.2.1

1. maven安装

终端执行

vim ~/.bashrc

结尾处键入

export MAVEN_HOME=/User/dzgdp888/apache-maven-3.2.1
export PATH=${PATH}:${MAVEN_HOME}/bin

:wq保存并退出,并使环境变量立即生效

source ~/.bashrc
~ dzgdp888$ mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T01:37:52+08:00)
Maven home: /Users/dzgdp888/dev/apache-maven-3.2.1
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: zh_CN, platform encoding: EUC_CN
OS name: "mac os x", version: "10.11.2", arch: "x86_64", family: "mac"

证明maven安装成功

2. Eclipse的maven插件安装

安装验证:
重启eclipse, Help --> About Eclipse --> Installation Details
在Installed Software标签中检查刚才选择的模块是否在这个列表中

检查eclipse是否已经支持创建Maven项目:
File --> New --> Other ,找到Maven一项,如果展开一切正常,说明m2eclipse已经正确安装了。

3. maven工程导入

4.使用打jar包

dzgdp888:~ dzgdp888$ cd Desktop/storm
dzgdp888:storm dzgdp888$ ls
README.md       src         target
pom.xml         storm-example.iml   项目说明.txt
dzgdp888:storm dzgdp888$ mvn package

执行结果如下:

Running com.blogchong.storm.helloworld.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec

Results :

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

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ storm-example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.667 s
[INFO] Finished at: 2015-12-30T00:53:12+08:00
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
dzgdp888:storm dzgdp888$ 

BUILD SUCCESS即为打包成功,打包成功后jar包路径为工程target目录下的storm-example-0.0.1-SNAPSHOT.jar

dzgdp888:storm dzgdp888$ ls target/
archive-tmp
classes
maven-archiver
storm-example-0.0.1-SNAPSHOT.jar
surefire-reports
test-classes
dzgdp888:storm dzgdp888$ 

mvn assembly:assembly

打好的jar包同样存放在target文件夹下,本例中名字为storm-example-0.0.1-SNAPSHOT-jar-with-dependencies.jar

target目录

从上图可以看出,这两种方式打包后大小还是相差很大的。

上一篇 下一篇

猜你喜欢

热点阅读