首页 > 代码库 > Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境

Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境

---------------------------------------
博文作者:迦壹
博客标题:Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境
博客地址:http://idoall.org/home.php?mod=space&uid=1&do=blog&id=560
转载声明:可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明,谢谢合作!
---------------------------------------
 
目录:
  1、Maven介绍
    1.1、什么是Maven?
    1.2、Maven对项目的结构要求
    1.3、Maven的常用命令
  2、Mahout的官网在哪里?
  3、在哪里下载?需要哪些组件的支持?
  4、如何安装?
    4.1、Brew下载并安装JDK1.8
    4.2、Brew下载并安装Maven3.2.3
    4.3、修改Maven3.2.3的配置文件settings.xml
    4.4、Brew下载并安装Eclipse4.4
    4.5、Eclipse4.4安装Maven插件
    4.6、用Maven创建一个Hello World
    4.7、用Maven创建项目的pom.xml简单介绍
    4.8、使用Eclipse打开Maven创建的项目,在控制台输出Hello World
  5、扩展阅读
 
目录:
  1、Maven介绍
    1.1、什么是Maven?
  Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。
  Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司项目采用 Maven 的比例在持续增长。
 
 
    1.2、Maven对项目的结构要求
  Maven 使用惯例优于配置的原则 。它要求在没有定制之前,所有的项目都有如下的结构:

目录

目的

${basedir}

存放 pom.xml和所有的子目录

${basedir}/src/main/java

项目的 java源代码

${basedir}/src/main/resources

项目的资源,比如说 property文件

${basedir}/src/test/java

项目的测试类,比如说 JUnit代码

${basedir}/src/test/resources

测试使用的资源

  一个 maven 项目在默认情况下会产生 JAR 文件,另外 ,编译后 的 classes 会放在 ${basedir}/target/classes 下面, JAR 文件会放在 ${basedir}/target 下面。
 
 
    1.3、Maven的常用命令
?
1
2
3
4
5
6
7
8
9
10
11
12
13
mvn archetype:create 创建Maven项目
mvn compile 编译源代码
mvn deploy 发布项目
mvn test-compile 编译测试源代码
mvn test 运行应用程序中的单元测试
mvn site 生成项目相关信息的网站
mvn clean 清除项目目录中的生成结果
mvn package 根据项目生成的jar
mvn install 在本地Repository中安装jar
mvn eclipse:eclipse 生成eclipse项目文件
mvnjetty:run 启动jetty服务
mvntomcat:run 启动tomcat服务
mvn clean package -Dmaven.test.skip=true:清除以前的包后重新打包,跳过测试类

  2、Mahout的官网在哪里?
  http://maven.apache.org/
 
  3、在哪里下载?需要哪些组件的支持?
  Maven3.2.3,后面会使用brew来安装。
  Maven的安装需要有JDK的支持,这里我们使用JDK1.8,在安装时我们会使用brew来安装。
  Eclipse4.4,后面会使用brew来安装。
 
  关于Mac brew如果不懂如何安装,可以参考这里《mac10.9+php5.5.15+brew0.9.5的安装》。
 
  4、如何安装?
    4.1、Brew下载并安装JDK1.8
  #如果你没有装cask也可以使用下面的命令先查询一下
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
?  ~  pwd
/Users/lion/
?  ~  brew cask search java
==> Removing legacy Tap
==> Adding caskroom Tap
Cloning into ‘/usr/local/Library/Taps/caskroom/homebrew-cask‘...
remote: Counting objects: 51450, done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 51450 (delta 37), reused 5 (delta 2)
Receiving objects: 100% (51450/51450), 16.61 MiB | 26.00 KiB/s, done.
Resolving deltas: 100% (31783/31783), done.
Checking connectivity... done.
Tapped 1 formula
==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
==> We‘ll set permissions properly so we won‘t need sudo in the future
Password:
==> Exact match
java
==> Partial matches
eclipse-java           javafx-scene-builder
?  ~  brew cask info java
java: 1.8.0_20
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
/opt/homebrew-cask/Caskroom/java/1.8.0_20 (2 files, 210M)
https://github.com/caskroom/homebrew-cask/blob/master/Casks/eclipse-java.rb
==> Contents
  JDK 8 Update 20.pkg (install)
==> Caveats
This Cask makes minor modifications to the JRE to prevent issues with
packaged applications, as discussed here:
 
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361
 
If your Java application still asks for JRE installation, you might need
to reboot or logout/login.
 
Installing this Cask means you have AGREED to the Oracle Binary Code
License Agreement for Java SE at
 
    http://www.oracle.com/technetwork/java/javase/terms/license/index.html
 
?  ~  brew cask install java
==> Caveats
This Cask makes minor modifications to the JRE to prevent issues with
packaged applications, as discussed here:
 
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361
 
If your Java application still asks for JRE installation, you might need
to reboot or logout/login.
 
Installing this Cask means you have AGREED to the Oracle Binary Code
License Agreement for Java SE at
 
    http://www.oracle.com/technetwork/java/javase/terms/license/index.html
 
==> Downloading http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-ma
######################################################################## 100.0%
==> Running installer for java; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
==> installer: Package name is JDK 8 Update 20
==> installer: Installing at base path /
==> installer: The install was successful.
  java installed to ‘/opt/homebrew-cask/Caskroom/java/1.8.0_20‘ (2 files, 210M)
?  ~  java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

    4.2、brew下载并安装Maven3.2.3
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
?  ~  brew info maven
maven: stable 3.2.3
http://maven.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/maven.rb
?  ~  brew install maven
==> Downloading http://www.apache.org/dyn/closer.cgi?path=maven/maven-3/3.2.3/bi
==> Best Mirror http://mirrors.cnnic.cn/apache/maven/maven-3/3.2.3/binaries/apac
######################################################################## 100.0%
  /usr/local/Cellar/maven/3.2.3: 76 files, 8.0M, built in 4 seconds
?  ~  which mvn && mvn --version
/usr/local/bin/mvn
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T04:58:10+08:00)
Maven home: /usr/local/Cellar/maven/3.2.3/libexec
Java version: 1.8.0_20, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"

 
    4.3、修改Maven3.2.3的配置文件settings.xml
?
1
2
?  ~  mkdir /Users/lion/Documents/_my_soft/mavenrepo
?  ~  vi /usr/local/Cellar/maven/3.2.3/libexec/conf/settings.xml
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 设置Maven仓库的存放位置 -->
<localRepository>/Users/lion/Documents/_my_soft/mavenrepo</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
</mirrors>
<profiles>
</profiles>
</settings>

 
    4.4、brew下载并安装Eclipse4.4
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
?  ~  brew cask search eclipse
==> Partial matches
eclipse-ide     eclipse-jee     nodeclipse
eclipse-java        eclipse-platform
?  ~  brew cask info eclipse-ide
eclipse-ide: 4.4.0
http://eclipse.org/
Not installed
https://github.com/caskroom/homebrew-cask/blob/master/Casks/eclipse-ide.rb
==> Contents
  eclipse/Eclipse.app (link)
?  ~  brew cask install eclipse-ide
==> Downloading http://download.eclipse.org/technology/epp/downloads/release/lun
######################################################################## 100.0%
##可以看到Eclipse被安装到了目录/Users/lion/Applications/下面
==> Symlinking App ‘Eclipse.app‘ to ‘/Users/lion/Applications/Eclipse.app‘
 eclipse-ide installed to ‘/opt/homebrew-cask/Caskroom/eclipse-ide/4.4.0‘ (1461 files, 227M)

 
    4.5、Eclipse4.4安装Maven插件
  #打开Eclipse4.4,在上面的菜单栏,点击Help->Eclipse Marketplace,如下图:

 
 

  #在浏览器打开:http://www.eclipse.org/m2e/download/,然后同时将install的图标拖动到Eclipse Marketplace中,会弹出一个窗口,点击Confirm,后面就继续下一步,就完成了在线安装的过程。如下图:

 

 


  #安装完后,会提示让你重启Eclipse,重启后进入初始页面会发现如下变化,同时点击左上角菜单栏的Eclipse->Preferences,也可以看到我们现在有了Maven配置项,如下图:

 

 

    4.7、修改Eclipse4.4的Maven配置
  #配置Eclipse使用我们刚刚安装的Maven,在菜单栏点击Window->Preferences,打开参数配置窗口,点击Mavek->Installations,然后点击右侧的Add,添加我们刚才安装的Maven路径,如下图:

 
 

  #让Eclipse的Maven插件使用我们自定义的setting.xml文件,在菜单栏点击Window->Preferences,打开参数配置窗口,点击Mavek->User Settings,然后在Global Settings和User Settings中输入:/usr/local/Cellar/maven/3.2.3/libexec/conf/settings.xml,如下图:

 
 

    4.6、用Maven创建一个Hello World
  参考文章《maven3.2.3+eclipse4.4+JDK1.8+win8.1_64bit环境搭建》,demo可以复用。

    4.7、用Maven创建项目的pom.xml简单介绍
  参考文章《maven3.2.3+eclipse4.4+JDK1.8+win8.1_64bit环境搭建》,demo可以复用。

    4.8、使用Eclipse打开Maven创建的项目,在控制台输出Hello World
  参考文章《maven3.2.3+eclipse4.4+JDK1.8+win8.1_64bit环境搭建》,demo可以复用。


  5、扩展阅读
  Maven3常用POM属性及Settings属性介绍:http://blog.csdn.net/lgm277531070/article/details/6922645
  Maven Settings:http://maven.apache.org/ref/3.2.3/maven-settings/settings.html
  Maven pom.xml 配置详解:http://blog.csdn.net/ithomer/article/details/9332071
  POM Reference:http://maven.apache.org/pom.html

Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境