maven多模块项目安装及使用

来源:互联网 发布:mac机如何配置ant 编辑:程序博客网 时间:2024/04/29 08:06

 

maven多工程项目安装管理

 

一、         检查JDK安装

 

建议安装jdk1.8

 

二、         Maven下载安装

下载地址:http://maven.apache.org/download.cgi

1.    安装

直接解压缩到D:\apache-maven-3.2.3-bin

2.    配置环境变量

应用 windows键+Pause Break键调出系统信息面板,点击高级系统设置,再点击环境变量,在系统变量中新建一个变量,变量名为M2_HOME,变量值为我们的Maven安装目录(D:\apache-maven-3.2.3-bin)。点击确定,接着我们在系统变量中找到一个名为Path的变量,在其变量值的末尾加上%M2_HOME%\bin;,注意多个值之间需要有分号隔开。点击确定。至此,环境变量设置完成。

3.    本地仓库 vs. 远程仓库

运行Maven的时候,Maven所需要的任何构件都是直接从本地仓库获取的。如果本地仓库没有,它会首先尝试从远程仓库下载构件至本地仓库,然后再使用本地仓库的构件。

比如说,你的项目配置了junit-3.8的依赖,在你运行mvn test 的时候,Maven需要使用junit-3.8的jar文件,它首先根据坐标查找本地仓库,如果找到,就直接使用。如果没有,Maven会检查可用的远程仓库配置,然后逐个尝试这些远程仓库去下载junit-3.8的jar文件,如果远程仓库存在该文件,Maven会将其下载到本地仓库中,继而使用。如果尝试过所有远程仓库之后,Maven还是没能够下载到该文件,它就会报错。

Maven缺省的本地仓库地址为${user.home}/.m2/repository 也就是说,一个用户会对应的拥有一个本地仓库。

你也可以自定义本地仓库的位置,修改${user.home}/.m2/settings.xml :

<settings>

  ...

 <localRepository>D:\java\repository</localRepository>

  ...

</settings>

了解了本地仓库,接着了解一下Maven缺省的远程仓库,即Maven中央仓库。

安装好Maven之后,我们可以建立一个简单的项目,配置一些简单的依赖,然后运行mvn clean install,项目就构建好了。我们没有手工的去下载任何jar文件,这一切都是因为Maven中央仓库的存在,当Maven在本地仓库找不到需要的jar文件时,它会查找远程仓库,而一个原始的Maven安装就自带了一个远程仓库——Maven中央仓库。

这个Maven中央仓库是在哪里定义的呢?在我的机器上,我安装了maven-2.0.10,我可以找到这个文件:${M2_HOME}/lib/maven-2.0.10-uber.jar ,打开该文件,能找到超级POM:\org\apache\maven\project\pom-4.0.0.xml ,它是所有Maven POM的父POM,所有Maven项目继承该配置,你可以在这个POM中发现如下配置:

  <repositories>

    <repository>

      <id>central</id>

      <name>Maven RepositorySwitchboard</name>

      <layout>default</layout>

     <url>http://repo1.maven.org/maven2</url>

      <snapshots>

        <enabled>false</enabled>

      </snapshots>

    </repository>

  </repositories>

关于远程仓库的配置,下面的小节我会详细解释,这里我们只要知道,中央仓库的id为central,远程url地址为http://repo1.maven.org/maven2,它关闭了snapshot版本构件下载的支持。

 

 

修改本地仓库地址

修改D:\apache-maven-3.2.3-bin\conf\setting.xml文件

  找到上面所画红线的地方,将该段代码从注解中抽取出来,放到外面,如D:/mavenlib。即是Maven下载下来的资源存放的地方

  我们拷贝D:\apache-maven-3.2.3-bin\conf\setting.xml到自己的目录D:\mavenlib下面,与全局的setting分开。

 

安装完成后,执行mvn help:system命令,该命令会打印出所有的Java系统属性和环境变量。这些信息对于我们日常的编程工作很有帮助。这条命令的目的是为了让Maven执行一个真正的任务。我们可以从命令行输出看到Maven下载maven-help-plugin,包括pom文件和Jar文件。这些文件都被下载到了Maven本地仓库中。

现在打开用户目录,比如我目前的用户目录是C:\Users\jiancheng\,你可以在vista和windows7中找到类似的用户目录,而之前的windows版本,该目录应该是类似于C:\Documentand Settings\jiancheng\.

  在用户目录下,我们可以发现.m2文件夹。默认情况下,该文件夹下放置了Maven本地仓库.m2/repository。所有的Maven构件(artifact)都被存储到该仓库中,以方便重用。

 

 

 

4.    在POM中配置远程仓库

前面我们看到超级POM配置了ID为central的远程仓库,我们可以在POM中配置其它的远程仓库。这样做的原因有很多,比如你有一个局域网的远程仓库,使用该仓库能大大提高下载速度,继而提高构建速度,也有可能你依赖的一个jar在central中找不到,它只存在于某个特定的公共仓库,这样你也不得不添加那个远程仓库的配置。

这里我配置一个远程仓库指向中央仓库的中国镜像:

<project>

...

 <repositories>

    <repository>

     <id>maven-net-cn</id>

     <name>Maven China Mirror</name>

     <url>http://maven.net.cn/content/groups/public/</url>

     <releases>

       <enabled>true</enabled>

     </releases>

     <snapshots>

       <enabled>false</enabled>

     </snapshots>

   </repository>

 </repositories>

 <pluginRepositories>

   <pluginRepository>

     <id>maven-net-cn</id>

     <name>Maven China Mirror</name>

     <url>http://maven.net.cn/content/groups/public/</url>

     <releases>

       <enabled>true</enabled>

     </releases>

     <snapshots>

       <enabled>false</enabled>

     </snapshots>   

   </pluginRepository>

 </pluginRepositories>

...

</project>

 

我们先看一下<repositories>的配置,你可以在它下面添加多个<repository> ,每个<repository>都有它唯一的ID,一个描述性的name,以及最重要的,远程仓库的url。此外,<releases><enabled>true</enabled></releases>告诉Maven可以从这个仓库下载releases版本的构件,而<snapshots><enabled>false</enabled></snapshots>告诉Maven不要从这个仓库下载snapshot版本的构件。禁止从公共仓库下载snapshot构件是推荐的做法,因为这些构件不稳定,且不受你控制,你应该避免使用。当然,如果你想使用局域网内组织内部的仓库,你可以激活snapshot的支持。

关于<repositories>的更详细的配置及相关解释,请参考:http://www.sonatype.com/books/maven-book/reference_zh/apas02s08.html。

至于<pluginRepositories>,这是配置Maven从什么地方下载插件构件(Maven的所有实际行为都由其插件完成)。该元素的内部配置和<repository>完全一样,不再解释。

 

 

5.    仓库管理器nexus

  上文中提到了本地仓库、远程仓库,Maven缺省的本地仓库地址为${user.home}/.m2/repository

肯定有人要说,全世界的maven开发者都去访问这个中央仓库?那它的压力得有多大啊!还有如果我的网速不够理想,下载一次构件都耗费好长时间啊。这都是一些典型的问题,就是因为这些问题,nexus应运而生了。详情看下面的章节。

三、         仓库管理器Nexus

本章节的内容可以放到最后再看。

1.    nexus介绍

nexus其实是一个仓库管理器,在使用maven的时候,你通常可以从中央仓库获取需要的构件,但这通常不是一个好的做法,你应该在本地架设一个Maven仓库服务器,在代理远程仓库的同时维护本地仓库,以节省带宽和时间,Nexus就可以满足这样的需要。说的通俗一点儿,就是在本地maven仓库和中央仓库之间再建一个中间仓库,本地仓库如果需要下载构件可以先去这个仓库管理器获取,如果仓库管理器有了那么直接就可以用,如果仓库管理器没有那么由它去中央仓库获取。通常,在一个公司内部,可以创建公司级的仓库管理器,相当于一个公司只有这个仓库管理器去和中央仓库打交道,而这个仓库管理器通常设置在公司内网,大大减轻了从中央仓库获取构件的带宽和不必要的磁盘浪费。

nexus还提供了强大的仓库管理功能,构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,它占用较少的内存,基于简单文件系统而非数据库。这些优点使其日趋成为最流行的Maven仓库管理器。

 

 

2.    nexus下载

http://www.sonatype.org/nexus/go/

3.    nexus安装

下载完,解压缩后可以看到两个文件夹,一个是nexus-2.9.2-01,另一个是sonatype-work,我们只需要将nexus-2.9.2-01拷贝到需要安装的路径即可,比如在我的机器上,我copy到了D:\apache-maven-3.2.3-bin目录下,sonatype-work可以不拷贝。

很简单,这就安装完了。

4.    nexus启动

nexus已经将各个平台的启动脚本都写好了,并分开目录放置,具体可以查看nexus-2.9.2-01\bin\jsw目录,我的机器是windows64位的,就可以进入到windows-x86-64目录下,点击console-nexus.bat即可启动,启动完成后,访问url:http://localhost:8081/nexus即可看到nexus的页面,如果是其他平台,找到对应的目录启动脚本即可。

到这里为止,我们的nexus就已经启动起来了,下一节,我们来讨论一下如何配置nexus。

5.    nexus管理

 

上一章节,我们讲述了nexus的概况和安装,并且成功启动了nexus,这一节我们讨论下nexus是如何工作的,如果来配置和管理nexus的。

接着上一节,我们启动了nexus后,可以通过浏览器访问到nexus的管理界面:http://localhost:8081/nexus。管理员登陆密码默认为:admin/admin123,UI界面是Ext来搭建的,操作起来没有什么障碍,而且界面看起来很清爽。

好,我们输入用户名密码开始来配置nexus。

输入用户名密码登陆进去之后,看到如下界面:左侧分为4部分,其中views/repositories是仓库相关的管理项;security是安全权限相关的;administrotr是管理相关的;help是帮助相关的。

 

5.1.  仓库配置-仓库浏览

点击左侧的“views/repositories–>repositories”,右边列出来了nexus默认的仓库,其中有四种类型的仓库,分别是hosted、proxy、virtual、group

  1. hosted,宿主型的,实实在在由nexus给管理的仓库,nexus自带了3个宿主仓库
  2. proxy,代理型的,每个仓库都是对一个远程仓库的代理,这其中就包括了对中央仓库的代理
  3. virtual,虚拟型的,这个不太了解,就不说了
  4. group,严格来说它不是一个仓库,顾名思义,是组的意思,它相当于是由多个仓库合成了一个组,由该组的url对外提供服务,nexus默认有两个组,一个是public group,其中包含了上边的3个宿主仓库和中央仓库;另一个是public snapshots group,里边包含了Apache Snapshots和CodeHaus Sanpshots。当然这些组包含的内容是可以修改的。

同时,nexus提供了增加、删除、修改仓库定义的功能。

 

 

5.2.  仓库配置-打开远程索引下载

上一篇文章咱们也提到了,巨大的用户访问中央仓库会带来巨大的网络压力和服务器压力,因此在nexus中默认的各个代理仓库的索引都是关闭状态,即安装完nexus后里边是空的,什么东东都没有,包括索引。我们现在要做的就是需要把这个索引给下载到nexus服务器中,以便使用者可以从nexus中搜索到相关构建。

方法如下:

  1. 选中中央仓库这条记录,即名字为central的仓库

  1. 下边选中configuration选项卡,找到其中的Download Remote Indexes,把fasle改为true,并保存

  1. 在上边的中央仓库记录上点击右键,选择update index

  1. 下载完成后然后在下边选中Browse Index选项卡,打开central这颗树的节点,应该能看到内容。在下载索引之前是空的。在上面的步骤中,update index是不会显示任务信息的,如果在下图中,看不到内容,点Refresh按钮,有时会很慢,等……。可能会提示超时,或远程maven库地址不正确,验证的方式一是点击下图的Browse Remote查看,远程仓库内容,如果能看到说明远程地址没有问题。二是通过浏览器看看地址可用否。

其他的proxy类型的仓库,都可以用同样的方法来下载索引。

注意:这一步仅仅是下载了远程仓库的索引,真正的构件还没有下载到nexus中。等真正有实际用户使用这些构件的时候,才会从中央仓库下载需要的构件文件。

 

5.3.  仓库配置-搜索构件

在使用maven之前,如果我们的项目中需要使用一个jar包,我们一般会怎么做呢?举个例子,我们要使用dom4j这个包,那么我们一般要去官方网站下载或者去baidugoogle里边直接搜索,版本呢只能逮到哪个是哪个了。这种情况如果找一个两个jar还行,如果多了将会带来巨大的工作量,而且还非常容易导致缺包、冲突等问题。

   现在有了maven,工作将会变的非常简单。还以找dom4j这个jar来举例子,在nexus的页面中搜索“dom4j”这个词,看如下结果左侧的搜索框输入了dom4j,右侧上方出现了所有包含dom4j的项目,加入我们需要1.6.1版本的dom4jjar,那么点击相应的条目在下方就会列出来。搜索到之后怎么用呢?右侧给出了依赖xml格式的数据,只需要将该xml  copy到你的pom.xml中,那么你的项目将会自动从nexus下载(注:项目中配置nexus的方法还没说,下一篇文章细说)。

说到这里,可能会有疑问,那假如说我的项目需要A.jar,但是A.jar又依赖B.jar,那我是不是还要依次去找所有的依赖jar呢?答案是否定的,maven已经给你提供了最简单的方法,只要你依赖了A.jar,那么A.jar所需要的所有jar它将自动帮你查找下载。怎么样,省事了很多吧。

5.4.  仓库配置-创建仓库

我们来做一个创建proxy类型的仓库,点击仓库里边上方的“Add….—>ProxyRepository”

 

Id是唯一的,输入一个名字,Remote Storage Location输入jbossmaven仓库地址,下边的代理相关的设置根据自己的情况来确定,输入完后点击保存即可。创建完成后按照5.2节提供的方法下载索引即可。

 

5.5.  仓库配置-组管理

组是若干仓库的一个集合,那么如何来管理组中包含的仓库呢?看下图:选中public Repositories这条记录,选中下方的configuration选项卡,左侧列出了已经选择的仓库列表,右边是可选的,通过中间的箭头来控制仓库列表信息。

5.6.  管理相关-代理设置

  如果nexus服务器上网需要设置代理,那么需要在Administration–>Server中设置,如下图所示:

5.7.  修改帐户密码

  Security-->Users中配置,在deployment用户上点击右键,选择SetPassword,然后设置一个密码,做这个操作是为了后面提交做准备 

 

6.    nexus配置

6.1.  配置nexus简介

 

上一篇文章,我们讨论了nexus的管理与基本配置。那么,当nexus配置完了之后,就相当于我们本地项目与maven中央仓库这个桥梁已经搭好了,剩下的就是看怎么通过怎样的配置来使用nexus。在本地开发的时候,主要牵涉到两个配置文件,一个是settings.xml%M2_HOME%/conf/settings.xml%USER_HOME%\.m2\settings.xml),一个是项目中的pom.xml。所有的主要配置都集中在这两个配置文件中,下边咱们就通过一个实际的项目的例子来说说这两个配置文件的用法。

 

我们打开父项目platformpom.xml文件,里边可以找到:

<groupId>com.chenrui.platform</groupId>

  <artifactId>platform</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>pom</packaging>

  <name>Intergrated Platform</name>

<description>Intergrated Platform</description>

 

<modules>

    <module>platform-parent</module>

    <module>platform-common-project</module>

    <module>platform-system-project</module>

    <module>platform-configration-project</module>

    <module>platform-webservice-project</module>

    <module>platform-mq-project</module>

    <module>platform-web-parent</module>

</modules>

 

在子项目的pom.xml的文件中,也能找到类似的

<parent>

   <artifactId>platform</artifactId>

   <groupId>com.chenrui.platform</groupId>

   <version>0.0.1-SNAPSHOT</version>

 </parent>

  <groupId>com.chenrui.platform</groupId>

  <artifactId>platform-common-project</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>pom</packaging>

  <name>platform-common-project</name>

  <description>public basic warehouse for company(公司公共通用类库)</description>

  <modules>

    <module>platform-common</module>

  </modules>

 

也就是说,在父项目和子项目中,都有说明他们之间的关系。

我们知道maven父项目和子项目的pom.xml是有继承关系的,也就是说各个模块相同的部分,我们可以配置到父项目的pom.xml文件中,这样子项目中的pom.xml只放自己个性的东西就可以了,这大大减少了工作量。另外,在编译和打包等其他阶段,都可以统一在父项目中来进行,maven会自动操作其中的子项目,提高了效率。

【注意:】事实上,所有的maven项目都会继承一个超级pom,这个pom就是%M2_HOME%\lib\maven-2.2.1-uber.jar中的org\apache\maven\project\pom-4.0.0.xml

6.2.  配置nexus

nexus里可以配置3种类型的仓库,分别是proxyhostedgroup 

proxy是远程仓库的代理。比如说在nexus中配置了一个central repositoryproxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用 

hosted是宿主仓库,用户可以把自己的一些构件,deployhosted中,也可以手工上传构件到hosted里。比如说oracle的驱动程序,ojdbc6.jar,在central repository是获取不到的,就需要手工上传到hosted 

group是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了

 

一般会配置3hosted repository,分别是3rd partySnapshotsReleases,分别用来保存第三方jar(典型的比如ojdbc6.jar),项目组内部的快照、项目组内部的发布版 

 

 

创建组group,组名为321

创建proxy,名为321-proxy 地址为http://maven.oschina.net/content/groups/public/,默认的Central的Remote StorageLocation 为https://repo1.maven.org/maven2/

创建hosted

  321-3rd party

  321-snapshots

  321-releases

我们知道,我们假设仓库管理器的目的是为了减少与中央仓库的交互,既然这样,那我们在本地肯定要配置nexus的相关信息,以便能够把中央仓库的配置覆盖掉,从而真正来使用nexus

两个步骤:

1.打开settings.xml文件(D:\apache-maven-3.2.3-bin\conf

找到<servers>标签,加入下面的内容

<server> 

       <id>releases</id> 

       <username>admin</username> 

       <password>admin123</password> 

   </server> 

   <server> 

       <id>snapshots</id> 

       <username>admin</username> 

       <password>admin123</password> 

   </server>

 

 

 

找到mirrors标签,在其中添加下边的配置,其中的localhots:8081根据自己的具体情况修改。

 

<mirror>

       <id>nexus</id>

        <name>internal nexusrepository</name>

       <mirrorOf>*</mirrorOf><!--central,oschinaRepository多个可以用*-->

       <!--url>http://localhost:8081/nexus/content/groups/public</url-->

       <url>http://localhost:8081/nexus/content/groups/321/</url>

     </mirror>

 

<profiles> 

   <profile> 

     <id>nexus</id> 

     <repositories> 

       <repository> 

         <id>central</id> 

         <url>http://localhost:8081/nexus/content/groups/321/</url> 

         <releases><enabled>true</enabled></releases> 

         <snapshots><enabled>true</enabled></snapshots> 

       </repository> 

     </repositories> 

    <pluginRepositories> 

        <pluginRepository> 

         <id>central</id> 

         <url>http://localhost:8081/nexus/content/groups/321/</url> 

         <releases><enabled>true</enabled></releases> 

         <snapshots><enabled>true</enabled></snapshots> 

       </pluginRepository> 

     </pluginRepositories> 

   </profile> 

 </profiles> 

 

 <activeProfiles> 

   <activeProfile>nexus</activeProfile> 

 </activeProfiles> 

 

 

2.打开父项目的pom.xml文件,添加如下配置:

 

 

<!-- 设定团队持续集成发布包服务器 -->

    <distributionManagement>

        <repository>

            <id>releases</id>

            <name>TeamNexus Release Repository</name>

            <url>http://localhost:8081/nexus/content/repositories/321-releases/</url>

        </repository>

 

        <snapshotRepository>

            <id>snapshots</id><!-- id要与上面setting.xml中的server中的配置一致 -->

            <name>TeamNexus distribution snapshot repository</name>

            <url>http://localhost:8081/nexus/content/repositories/321-snapshots/</url>

            <uniqueVersion>false</uniqueVersion>

        </snapshotRepository>

    </distributionManagement>

 

 

    <!-- 指定Maven仓库 -->

    <repositories>

        <!-- 官方maven仓库 -->

        <repository>

            <id>maven</id>

            <name>Maven Repository Switchboard</name>

            <url>http://repo1.maven.org/maven2</url>

            <layout>default</layout>

            <snapshots>

                <enabled>true</enabled>

            </snapshots>

        </repository>

 

        <!-- oschinamaven仓库 -->

        <repository>

            <id>oschinaRepository</id>

            <name>local privatenexus</name>

            <url>http://maven.oschina.net/content/groups/public/</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>true</enabled>

            </snapshots>

        </repository>

    </repositories>

 

 

    <!-- 指定mavenplugin仓库 -->

    <pluginRepositories>

       <!-- 官方maven仓库 -->

        <pluginRepository>

            <id>central</id>

            <name>Central Repository</name>

            <url>http://repo1.maven.org/maven2</url>

            <layout>default</layout>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

            <releases>

                <updatePolicy>never</updatePolicy>

            </releases>

        </pluginRepository>

   

   

        <!-- oschinamavenplugin仓库 -->

        <pluginRepository>

            <id>oschinaPluginRepository</id>

            <name>local privatenexus</name>

            <url>http://maven.oschina.net/content/groups/public/</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

        </pluginRepository>

    </pluginRepositories>

 

其中的localhots:8081根据自己的具体情况修改。

 

好了,就这么简单,就配置好了,如何验证一下项目真的不去找中央仓库的麻烦了呢?可以这么测试一下,你把你项目中使用到的一些构件在本地的maven仓库删除掉,然后再编译一下项目,在控制台打印的日志中,你能够清晰的看到都是从nexusdownlaod的,而在之前都是打印从中央仓库获取的。

四、         安装m2eclipse

 

eclipse在线安装

启动eclipse 4.4之后,在菜单栏中选择help,然后选择Install NewSoftware…,接着你会看到一个Install对话框,在Work with字段中输入http://m2eclipse.sonatype.org/update/,然后点击Add,弹出Add Site对话框,在Name字段中输入m2eclipse,点击ok。Eclipse会下载m2eclipse安装站点上的资源信息。等待资源载入完成之后,我们再将其全部展开,就能看到如下的界面:

 

 

如果一切没问题,我们再检查一下现在eclipse是否已经支持创建Maven项目,点击新建菜单,选择other,在弹出的对话框中,找到maven一项,能够看到如下对话框,选择安装成功。

 

 

 

 

不要使用IDE内嵌Maven

不论是eclipse还是netbeans,当我们集成maven的时候,都会安装上一个内嵌的maven,这个内嵌的maven通常会比较新,但不一定稳定。

   在m2eclipse环境中,点击菜单栏中的windows,然后选择prefrences,在弹出的对话框中展开左边的maven项,选择installation子项,在右边的面板中,我们能够看到一个默认的embedded maven安装被选中了,点击add…然后选择我们的maven安装目录 M2_HOME,添加完毕之后,选择一个外部的Maven,如下图

 

 

Myeclipse安装

由于Myeclipse已经自带maven插件,我们就不需要重新单独安装了,唯一需要修改的是Myeclipse中使用的maven版本,不管Myeclipse使用的是哪个版本,我们统一改成下载到本地安装的版本。只需指定maven的安装目录,指定setting文件即可

 

在菜单项中选择window—>preferences—>myeclipse—>maven4myeclipse—>maven—>installations,

点击右侧add按钮,选择本地maven的根目录,添加后,点击apply和ok按钮。

 

 

菜单项 window—>preferences—>myeclipse—>maven4myeclipse—>maven—>user setting

修改user settings 指定到本地maven的conf\setting.xml,点击update settings,apply 和ok。

安装完成。

配置项目属性

可以不配置。

如果在settings.xml中的profiles标签中添加:<profile>
<id>jdk-1.6</id>

<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.6</jdk>
</activation>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
</properties>
</profile>

那么MyEclipse将会默认生成jdk1.6的项目

五、         新建独立工程项目

 

1.    创建项目

创建项目:new > other > 搜索“maven”,双击“Maven Project”

点击下一步,选择“Create a simple project (skip archetype selection)”复选框

 

2.    添加groupId,artifactId

 

接上图,点击下一步,输入相关必要信息(如:Group Id,Artifact Id等),注意packagin 选择war,

groupId ,ArtifactId和version三行,这三个元素定义了一个项目基本的坐标,就像我们的身份证号码一样,在Maven的世界里,任务的jar,pom或者war都是以基于这些基本的坐标进行区分的。

groupId 定义了项目属于哪个组,这个组往往工项目所在的组织或公司存在关联,譬如你在googlecode上建立了一个名为myapp的项目,那么groupid就应该是com.googlecode.myapp,如果你的公司是mycom,有一个项目为myapp,那么groupid就应该是com.mycom.myapp。

   artifactId定义了当前maven项目在组中唯一的ID,我们为这个kq项目定义artifactId为kq,ztk项目定义为ztk。换句话说,在前面的groupId为com.googlecode.myapp的例子中,你可能会为不同的子项目(模块)分配artifactId,如

myapp-util、myapp-domain、myapp-web等等。

  Version顾名思议指定了项目当前的版本,snapshot意为快照,说明该项目还处于开发中,是不稳定的版本。随着项目的发展,version会不断更新,如升级为1.0、1.1-SNAPSHOT、1.1、2.0等。

   最后一个name元素声明了一个对于用户更为友好的项目名称,虽然这不是必须的,但我还是推荐为每一个POM声明name,以方便信息交流。

3.    完成项目创建

点击FInish完成,然后可能会提示一个错误框,这里不要管它,点击OK即可

 

4.    添加jar包方法

为了方便项目的测试,我们首先引入junit。通过网址http://search.maven.org/ 查询junit,找到junit4的引用 加入pom.xml中

将上图红色框选部分添加到pom.xml中,系统会自动下载相应的jar包到我们自定义的本地仓库中,如下图本地仓库

 

我们在上面添加了一个依赖,这个依赖的groupId是junit,artifactId是junit,version是4.11。前面我们提到groupId、artifactId和version是任何一个Maven项目最基本的坐标,Junit也不例外,有了这段声明,Maven就能够自动下载junit-4.11.jar(文件来自Maven仓库及中央仓库)。

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.11</version>

<scope>test</scope>

上述pom代码中还有一个元素scope,其值为test,scope为依赖范围,而为test时,表示该依赖只对测试有效,换句话说,我们在测试代码中import JUnit代码是没有问题的,但是如果我们在主代码中importJUnit代码,就会造成编译错误。如果不声明依赖范围,那么就是默认值是compile,表示该依赖对主代码和测试代码都有效。

 

5.    测试java项目

在src/test/java中创建一个测试类代码如下:

public class TestProject{

    @Test

    public void test01(){

        Assert.assertTrue(true);

    }

}

 

见到类似下面的页面,算是成功了

 

6.    修改java项目为web项目

下面我们开始将项目转换为web项目。项目右键-->myeclipse-->add web projectcapablities...

点击Finish,有可能会提示如下

MyEclipse has detected that your project uses custom outputfolders. If the output folder is not set to <webroot>/WEB-INF/classes,these classes will not be available to your web application. Click Yes to resetthe output folder or No to leave as is.

点击Yes,即可。该项目就可以加载到tomcatweb容器中了。

再次打开pom.xml文件发现多了很多依赖。这些都是myeclipse认为作为一个web项目需要的jar。可以根据项目实际情况进行修改。

 

如果第6步的时候我们选择错误了,还可以在项目属性中修改回来。具体方法是,项目右键-->properties-->myeclipse-->web

重新选择Web-rootfolder路径即可

7.    运行web项目

点击OK,项目创建成功。像以往的普通项目那样部署到 Tomcat 中,启动并访问创建的index.jsp。

 

 

六、         新建多模块项目

1.    设置支持多个子模块

所有用Maven管理的真实项目都应该是分模块的,每个模块都对应着一个pom.xml。它们之间通过继承和聚合(也称作多模块,multi-module)相互关联。

Maven的坐标GAV(groupId, artifactId, version)在这里进行配置,这些都是必须的。特殊的地方在于,这里的packaging为pom。所有带有子模块的项目的packaging都为pom。packaging如果不进行配置,它的默认值是jar,代表Maven会将项目打成一个jar包。

为了使MyEclipse里面的Maven工程支持多个子模块,需要设置:

打开Window -> Preferences ->  MyEclipse  -> Maven4MyEclipse,勾选“Support multiple Maven modules mapped to a single Eclipse workspaceproject”

2.    Maven项目创建-创建父项目

下面在MyEclipse中创建Maven项目。首先创建一个父项目,然后创建多个子项目。

创建父项目platform

打开New->Other->MyEclipse->Maven->MavenProject

下一步,将“Create a simple project (skip archetype selection)”复选框选中:

 

 

添加项目信息,如Group IdArtifactIdVersion。由于本项目是父项目,所以Packaging方式为pom

Group Id输入为com.chenrui.platform

Artiface Id输入platform-project(此名字将作为eclipse工作区中的项目名称),Packaging类型为pom

 

点击Finish完成后,见下图

别忘记将项目修改为utf-8编码格式。

 

修改pom.xml文件内容,最主要是配置modules为多个子项目(每个子项目下面还可以继续包含子项目),片段内容类似如下,具体创建子项目的过程请看下文“Maven项目创建-创建子项目为java项目”

<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.chenrui.platform</groupId>

  <artifactId>platform-project</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>pom</packaging>

  <name>Intergrated Platform</name>

  <description>kq,ztk,a1integerated</description>

 

  <modules>

   <module>platform-system</module> <!-- 用户管理、审核管理、日志管理 -->

    <module>platform-config</module>  <!--系统配置、检索配置 -->

   <module>platform-search</module>  <!--统一检索接口 -->

   <module>platform-search-web</module>  <!--统一检索接口 -->

    <module>platform-document</module>  <!--文档系统 -->

    <module>platform-kq</module> 

    <module>platform-ztk</module>

<module>platform-al</module>

 

 </modules>

</project>

 

3.    Maven项目创建-创建子项目为java项目

打开New->Other->MyEclipse->Maven->MavenModuleModule Name输入为platform-system-project,下一步,将“Create asimple project (skip archetype selection)”复选框选中:

 

 

针对上图,右键对platform项目刷新一下,就会将新建的playform-system-project子项目显示出来

 

打开项目的属性,Properties->Java Compiler,将版本号改为1.6,并且,将Java Build Path->LibrariesJRE修改为相应的版本如1.8

 

4.    Maven项目创建-创建子模块

针对上文3中的platform-system-project项目创建子模块。

创建子模块过程与创建子项目过程类似,右键选中子项目,platform-system-project

打开New->Other->MyEclipse->Maven->MavenModuleModule Name输入为platform-system-dao,下一步,将“Create asimple project (skip archetype selection)”复选框选中:

5.    Maven创建子项目为web项目-myeclipse 10

创建子项目为web项目有两种方式,一种是 “五、新建独立工程项目”的方式,先创建为Java项目后,再修改为子项目,下面介绍的是直接创建子项目为web项目。

打开New->Other->MyEclipse->Maven->Maven ModuleModule Name输入为platform-web-admin-project

,在Parent Project选择创建好的platform项目作为platform-web-admin-project的父项目:

 

 

下一步输入Group IdArtifact Id和版本号

点击Finish.可能出现错误如下图,直接点击确定。

看下图,展开部分还不具有web项目具备的相应的web-inf、lib等

下面我们开始将项目具有web项目的功能。针对下图中红色标记

项目右键-->myeclipse-->add web projectcapablities...

 

点击Browse…,选择当前platform-web-admin-project下面的目录,如下图中红色选中部分。

别忘记上图上中的jre为相应的版本。系统会自动将需要的jar包添加进来。

 

6.    Maven创建子项目为web项目-myeclipse2014

在myeclipse 2014中,在上节5中,项目右键-->myeclipse-->add web projectcapablities...

是不存在的。

 

7.    模块间的依赖关系配置

见下图,platform-system-project项目下面的两个模块之间的依赖,platform-system-service模块依赖platform-system-dao模块下面的代码。

 

添加依赖

右键platform-system-service模块,选择Maven4MyEclipse-> Add Dependency

 

maven的配置中的<scope></scope>详解

  (1)scope的默认值是compile,指的是编译时依赖,即编译时就会将依赖包下载到maven仓库中(缺省值,适用于所有阶段,会随着项目一起发布)

  (2)test:只有在测试的时候会依赖这个包,即打包的时候不会将配置为test的junit包加进去。(只在测试时使用,用于编译和运行测试代码。不会随项目发布)

        test项的包只对test源文件下的类起作用,如果将junit的代码放到src下,而junit配置为test将会出现找不到junit包的错误。
   (3)provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
   (4)runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
   (5)system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。

 

 

 

8.    统一平台maven架构

 

 

 

platform

 

 

 

 

 

 

 

 

 

 

Common-project

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

七、         java项目几个操作

这个更简单,在项目的任何一个文件中点击右键:RunAs–>Maven Package,看看在target目录下,是不是已经生成了helloworld.war

1.    编译

编译无依赖的模块

mvncompile,编译java项目,java文件将会被编译成class文件放到target/classes目录下

cmd 进入到项目源码所有的路径,如下图

由于platform-system-service模块依赖platform-system-dao模块,因此要先编译platform-system-dao

第一次构建会下载相应的jar,增加了 mvn compile -X -e增加了DEBUG信息,见下图,添加了debug信息

刷新platform看到编译后的class文件。

 

找开独立的项目模块 platform-system-dao(与模块platform-system-project显示平级的),运行

运行结果如下图

 

编译有依赖的模块

现在想运行platform-system-service模块(模块调用platform-system-dao模块),见下图

找不到主类,原因是还没有编译(记得在编译前添加依赖),执行下面的编译,出错了。

从上图可以看出找不到platform-system-dao.jar(通过下面的“打jar包”章节实现打包),即使打包也没有成功。

为什么?原因的由于platform-system-service模块在编译时会先找到父级的pom文件,在父级的pom文件没有编译的情况下,是无法找到platform-system-dao模块的,所以要直接针对父项目进行编译,见下图

上图编译成功后,可以运行了。查看下图运行结果。

清空编译(清除产生的项目)执行命令 mvn clean 此命令会把生成的jar,class文件全部删除

mvn  clean  //清除目标目录中的生成结果 delete target,即会清除生成的target目录

mvn clean install 删除再编译

 

 

2.    打jar包

无依赖模块打包

运行mvn package命令打包,见下图

项目将会打包成jar文件放到target目录下,jar文件的命名规则是:${project.artifactId}-${project.version}.jar

 

通过myeclipse针对项目右键,run as -> maven package即可完成。

 

有依赖模块打包

Platform-system-service模块依赖platform-system-dao模块,如何打包,直接针对platform-system-service模块是不会打包成功的,需要针对platform-system-project项目进行打包。

通过myeclipse针对项目右键,run as -> maven package即可完成。

[INFO] Scanning for projects...

[INFO]------------------------------------------------------------------------

[INFO] Reactor Build Order:

[INFO]

[INFO] platform-system-project

[INFO] platform-system-dao

[INFO] platform-system-service

[INFO] platform-system-entity

[INFO] platform-system-utils

[INFO]                                                                         

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-project 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]                                                                         

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-dao 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @ platform-system-dao---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-dao ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-dao ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-dao ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-dao ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-dao ---

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-service 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @ platform-system-service---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-service---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-service ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-service ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-service ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-service ---

[INFO] Building jar:D:\Workspaces8.6\platform\platform-system-project\platform-system-service\target\platform-system-service-0.0.1-SNAPSHOT.jar

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-entity 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] --- maven-resources-plugin:2.6:resources(default-resources) @ platform-system-entity ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-entity---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-entity ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-entity ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-entity ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-entity ---

[INFO] Building jar:D:\Workspaces8.6\platform\platform-system-project\platform-system-entity\target\platform-system-entity-0.0.1-SNAPSHOT.jar

[INFO]                                                                         

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-utils 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-system-utils ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-utils ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-utils ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-utils ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-utils ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-utils ---

[INFO] Building jar:D:\Workspaces8.6\platform\platform-system-project\platform-system-utils\target\platform-system-utils-0.0.1-SNAPSHOT.jar

[INFO]------------------------------------------------------------------------

[INFO] Reactor Summary:

[INFO]

[INFO] platform-system-project............................ SUCCESS [ 0.002 s]

[INFO] platform-system-dao................................ SUCCESS [ 1.996 s]

[INFO] platform-system-service............................ SUCCESS [ 0.122 s]

[INFO] platform-system-entity............................. SUCCESS [ 0.024 s]

[INFO] platform-system-utils.............................. SUCCESS [ 0.021 s]

[INFO]------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO]------------------------------------------------------------------------

[INFO] Total time: 2.392 s

[INFO] Finished at:2014-10-10T09:21:33+08:00

[INFO] Final Memory: 10M/167M

[INFO]------------------------------------------------------------------------

 

3.    安装

无依赖模块安装

安装的作用是将打包好的jar文件安装到本地的maven仓库中,以供其他项目(如果其他项目依赖该项目的话)使用。

mvninstall,在maven仓库中存放的目录结构是:${project.groupId}–>${project.artifactId}–>${project.version}

 

安装后,看上图红色部分,看下图

 

通过myeclipse直接在项目上右键 run as -> maven install即可。

有依赖模块安装

针对父级项目执行mvn install命令

下面对整个项目install,部署到本地仓库中

[INFO] Scanning for projects...

[INFO]------------------------------------------------------------------------

[INFO] Reactor Build Order:

[INFO]

[INFO] platform-system-project

[INFO] platform-system-dao

[INFO] platform-system-service

[INFO] platform-system-entity

[INFO] platform-system-utils

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Building platform-system-project0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-project---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\pom.xml toC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-project\0.0.1-SNAPSHOT\platform-system-project-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO] ------------------------------------------------------------------------

[INFO] Buildingplatform-system-dao 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @ platform-system-dao---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-dao ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-dao ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] --- maven-compiler-plugin:3.1:testCompile(default-testCompile) @ platform-system-dao ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-dao ---

[INFO]

[INFO] --- maven-jar-plugin:2.4:jar(default-jar) @ platform-system-dao ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-dao ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-dao\target\platform-system-dao-0.0.1-SNAPSHOT.jartoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-dao\0.0.1-SNAPSHOT\platform-system-dao-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-dao\pom.xmlto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-dao\0.0.1-SNAPSHOT\platform-system-dao-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-service 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @ platform-system-service---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-service---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-service ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-service ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-service ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-service ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-service---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-service\target\platform-system-service-0.0.1-SNAPSHOT.jartoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-service\0.0.1-SNAPSHOT\platform-system-service-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-service\pom.xmltoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-service\0.0.1-SNAPSHOT\platform-system-service-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-entity 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-system-entity ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-entity---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-entity ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-entity ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-entity ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-entity ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-entity ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-entity\target\platform-system-entity-0.0.1-SNAPSHOT.jartoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-entity\0.0.1-SNAPSHOT\platform-system-entity-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-entity\pom.xmltoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-entity\0.0.1-SNAPSHOT\platform-system-entity-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO] ------------------------------------------------------------------------

[INFO] Buildingplatform-system-utils 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-system-utils ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-utils ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-utils ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-utils ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-utils ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-utils ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-utils ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-utils\target\platform-system-utils-0.0.1-SNAPSHOT.jartoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-utils\0.0.1-SNAPSHOT\platform-system-utils-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-utils\pom.xmltoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-utils\0.0.1-SNAPSHOT\platform-system-utils-0.0.1-SNAPSHOT.pom

[INFO]------------------------------------------------------------------------

[INFO] Reactor Summary:

[INFO]

[INFO] platform-system-project............................ SUCCESS [ 0.414 s]

[INFO] platform-system-dao................................ SUCCESS [ 1.803 s]

[INFO] platform-system-service............................ SUCCESS [ 0.133 s]

[INFO] platform-system-entity............................. SUCCESS [ 0.055 s]

[INFO] platform-system-utils.............................. SUCCESS [ 0.041 s]

[INFO]------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 2.591 s

[INFO] Finished at:2014-10-10T09:24:16+08:00

[INFO] Final Memory: 10M/164M

[INFO]------------------------------------------------------------------------

 

4.    部署

部署的作用是将打包好的jar文件上传到nexus中,以供其他同伴(如果其他同伴依赖该项目的话)使用。

mvndeploy  看下面的图,显示部署失败,失败的原因repostroy element was not specified in the pominside distributionManagement element or in ……

见到上面的错误,我们在platform中加入下面的内容

<!-- 设定团队持续集成发布包服务器  -->

    <distributionManagement>

       <repository>

           <id>nexus</id>

           <name>TeamNexus Release Repository</name>

           <url>http://localhost:8081/nexus/content/repositories/releases</url>

       </repository>

      

       <snapshotRepository>

           <id>snapshot</id>

           <name>TeamNexus Snapshot Repository</name>

           <url>http://localhost:8081/nexus/content/repositories/snapshots</url>

           <uniqueVersion>false</uniqueVersion>

       </snapshotRepository>

</distributionManagement>

再次执行,见到下面的错误

在这里要注意,在部署的时候,会提示401错误,此时你需要在setting.xml文件中添加鉴权信息,即在部署的时候需要使用nexus给分配的账户来上传。

settings.xml中找到servers标签,在其中添加如下配置:

<server>
<id>
nexus</id>
<username>admin</username>
<password>admin123</password>
</server>

<server>
<id>
snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>

其中的用户名和密码是nexus分配的,其中的id一定要和父项目中pom.xml文件中刚才配置的repositorysnapshotRepositoryid一致。

红色加重的“nexus”与下图中的框选的“nexus”一致。

<!-- 设定团队持续集成发布包服务器  -->

    <distributionManagement>

       <repository>

           <id>nexus</id>

           <name>TeamNexus Release Repository</name>

           <url>http://localhost:8081/nexus/content/repositories/releases</url>

       </repository>

      

       <snapshotRepository>

           <id>snapshot</id>

           <name>TeamNexus Snapshot Repository</name>

           <url>http://localhost:8081/nexus/content/repositories/snapshots</url>

           <uniqueVersion>false</uniqueVersion>

       </snapshotRepository>

</distributionManagement>

经过上面的修改后,部署成功

部署成功

 

 

 

 

通过myeclipse直接在项目上右键 run as -> maven deploy即可。

 

 

八、         Web项目运行

新建一个子项目为web项目,详细创建过程参照“六、新建多模块项目–>  5.Maven创建子项目为web项目”,

新建一个最简单的Hello Word程序

新建的Servlet程序

package com.chenrui.platform.web.admin.user;

 

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

 

import com.chenrui.platform.system.service.UserMgmtService;

importcom.chenrui.platform.system.service.impl.UserMgmtServiceImpl;

 

public class HelloWord extends HttpServlet {

   

    UserMgmtService userMgmtService =new UserMgmtServiceImpl();

    public void addUser(){

       System.out.println("action类方法 addUser方法调用");

       userMgmtService.addUser();

    }

   

    protected void service(HttpServletRequest request,HttpServletResponse response)

        throws ServletException,IOException {

        //ServletOutputStream out = response.getOutputStream();

    addUser();

        PrintWriter out = response.getWriter();

        out.println("Hello world!");

    }

}

在web.xml中添加配置

  <!--设置相应Servlet对应的类型-->

    <servlet>

        <servlet-name>helloWord</servlet-name>

        <servlet-class>com.chenrui.platform.web.admin.user.HelloWord</servlet-class>

    </servlet>

   

    <!--设置请求对应的Servlet名称-->

    <servlet-mapping>

        <servlet-name>helloWord</servlet-name>

        <url-pattern>/helloWord</url-pattern>

    </servlet-mapping>

 

通过Tomcat直接部署运行

  传统的方法,我们需要先去下载一个tomcat到本地,然后将项目发布到该tomcat中。

 

通过应用jetty容器部署运行

将platform-web-admin-project项目相应的依赖,如下图,红色部分。

下图开始配置jetty

在下图Maven Build中新建一个build,如test,

通过Browse Workspace… 选择web项目

指定Goals为jetty:run

点击运行,开始下载插件。

 

下图,附带说明一下,目标

 

通过下面的方式运行jetty

通过上图可以看出,“No plugin found for prefix ‘jetty’ in thecurrent project and in the plugin groups …”

没有安装jetty插件,

安装jetty插件,将下面的配置信息添加到platform-web-admin-project项目的pom.xml文件中

<build>

      <plugins>

         <plugin>

               <groupId>org.mortbay.jetty</groupId>

               <artifactId>maven-jetty-plugin</artifactId>

               <version>6.1.10</version>

               <configuration>

                       <scanIntervalSeconds>10</scanIntervalSeconds>

                       <stopKey>foo</stopKey>

                       <stopPort>9999</stopPort>

               </configuration>

               <executions>

                       <execution>

                               <id>start-jetty</id>

                               <phase>pre-integration-test</phase>

                               <goals>

                                      <goal>run</goal>

                               </goals>

                               <configuration>

                                      <scanIntervalSeconds>0</scanIntervalSeconds>

                                      <daemon>true</daemon>

                               </configuration>

                       </execution>

                       <execution>

                               <id>stop-jetty</id>

                               <phase>post-integration-test</phase>

                               <goals>

                                      <goal>stop</goal>

                               </goals>

                       </execution>

               </executions>

       </plugin>

   

      </plugins>

  </build>

再次运行出现下图中的错误“Failed to execute goal on projectplatform-web-admin-project: Could not resolve dependencies for projectcom.chenrui.platform:platform-web-admin-project:war:0.0.1-SNAPSHOT: Could notfind artifact com.chenrui.platform:platform-system-service:jar:0.0.1-SNAPSHOT-> [Help 1]”

 

 

[INFO] Scanning for projects...

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-web-admin-project 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] >>>maven-jetty-plugin:6.1.10:run (default-cli) > test-compile @platform-web-admin-project >>>

[INFO]------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO]------------------------------------------------------------------------

[INFO] Total time: 0.370 s

[INFO] Finished at:2014-10-10T09:46:26+08:00

[INFO] Final Memory: 8M/116M

[INFO]------------------------------------------------------------------------

[ERROR] Failed to execute goalon project platform-web-admin-project: Could not resolve dependencies forproject com.chenrui.platform:platform-web-admin-project:war:0.0.1-SNAPSHOT:Failed to collect dependencies atcom.chenrui.platform:platform-system-project:pom:0.0.1-SNAPSHOT: Failed to readartifact descriptor for com.chenrui.platform:platform-system-project:pom:0.0.1-SNAPSHOT:Could not find artifact com.chenrui.platform:platform:pom:0.0.1-SNAPSHOT -> [Help 1]

[ERROR]

[ERROR] To see the full stacktrace 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 informationabout the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

通过上面的错误可以看出,platfomr-web-admin-project项目的父级项目platform没有安装,所以在项目结构创建好后,可以直接将最顶级的父项目安装到本地仓库中。

[INFO] Scanning for projects...

[INFO]------------------------------------------------------------------------

[INFO] Reactor Build Order:

[INFO]

[INFO] Intergrated Platform

[INFO] platform-parent

[INFO] platform-common-project

[INFO] platform-common

[INFO] platform-system-project

[INFO] platform-system-dao

[INFO] platform-system-service

[INFO] platform-system-entity

[INFO] platform-system-utils

[INFO] platform-configration-project

[INFO]platform-configration-dao

[INFO]platform-configration-service

[INFO]platform-configration-entity

[INFO]platform-configration-utils

[INFO]platform-webservice-project

[INFO] platform-webservice-solr

[INFO]platform-webservice-solr-client

[INFO]platform-webservice-solr-server

[INFO]platform-webservice-solr-pojo

[INFO]platform-webservice-solr-utils

[INFO] platform-mq-project

[INFO] platform-web-parent

[INFO] platform-web-common

[INFO] platform-web-system

[INFO] platform-web-configration

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Building IntergratedPlatform 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform ---

[INFO] InstallingD:\Workspaces8.6\platform\pom.xml toC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform\0.0.1-SNAPSHOT\platform-0.0.1-SNAPSHOT.pom

 [INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-project 0.0.1-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-project---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\pom.xml to C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-project\0.0.1-SNAPSHOT\platform-system-project-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-dao 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @ platform-system-dao---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-dao ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-system-dao ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-dao ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-dao ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-dao ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-dao ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-dao\target\platform-system-dao-0.0.1-SNAPSHOT.jarto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-dao\0.0.1-SNAPSHOT\platform-system-dao-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-dao\pom.xmlto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-dao\0.0.1-SNAPSHOT\platform-system-dao-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-service 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-system-service ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-service---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] --- maven-resources-plugin:2.6:testResources(default-testResources) @ platform-system-service ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @ platform-system-service---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-service ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-service ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-service---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-service\target\platform-system-service-0.0.1-SNAPSHOT.jarto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-service\0.0.1-SNAPSHOT\platform-system-service-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-service\pom.xmlto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-service\0.0.1-SNAPSHOT\platform-system-service-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-entity 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-system-entity ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-entity---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] --- maven-resources-plugin:2.6:testResources(default-testResources) @ platform-system-entity ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-entity ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-entity ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-entity ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-entity ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-entity\target\platform-system-entity-0.0.1-SNAPSHOT.jarto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-entity\0.0.1-SNAPSHOT\platform-system-entity-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-entity\pom.xmlto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-entity\0.0.1-SNAPSHOT\platform-system-entity-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-system-utils 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-system-utils ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-system-utils ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] --- maven-resources-plugin:2.6:testResources(default-testResources) @ platform-system-utils ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-system-utils ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-system-utils ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-system-utils ---

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-system-utils ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-utils\target\platform-system-utils-0.0.1-SNAPSHOT.jarto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-utils\0.0.1-SNAPSHOT\platform-system-utils-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-system-project\platform-system-utils\pom.xmlto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-system-utils\0.0.1-SNAPSHOT\platform-system-utils-0.0.1-SNAPSHOT.pom

 [INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-webservice-project 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @platform-webservice-project ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-webservice-project\pom.xml toC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-webservice-project\0.0.1-SNAPSHOT\platform-webservice-project-0.0.1-SNAPSHOT.pom

[INFO]                                                                         

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-webservice-solr 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-webservice-solr---

[INFO] InstallingD:\Workspaces8.6\platform\platform-webservice-project\platform-webservice-solr\pom.xmlto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-webservice-solr\0.0.1-SNAPSHOT\platform-webservice-solr-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-webservice-solr-client 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-webservice-solr-client ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @platform-webservice-solr-client ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-webservice-solr-client ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

… ….省略部分

 

 [INFO]                                                                         

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-web-system 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @ platform-web-system---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-web-system ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-web-system ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-web-system ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-web-system ---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-web-system ---

[INFO] Building jar:D:\Workspaces8.6\platform\platform-web-parent\platform-web-system\target\platform-web-system-0.0.1-SNAPSHOT.jar

[INFO]

[INFO] --- maven-install-plugin:2.4:install(default-install) @ platform-web-system ---

[INFO] InstallingD:\Workspaces8.6\platform\platform-web-parent\platform-web-system\target\platform-web-system-0.0.1-SNAPSHOT.jarto C:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-web-system\0.0.1-SNAPSHOT\platform-web-system-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-web-parent\platform-web-system\pom.xml toC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-web-system\0.0.1-SNAPSHOT\platform-web-system-0.0.1-SNAPSHOT.pom

[INFO]                                                                        

[INFO]------------------------------------------------------------------------

[INFO] Buildingplatform-web-configration 0.0.1-SNAPSHOT

[INFO]------------------------------------------------------------------------

[INFO]

[INFO] ---maven-resources-plugin:2.6:resources (default-resources) @platform-web-configration ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:compile (default-compile) @ platform-web-configration---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-resources-plugin:2.6:testResources (default-testResources) @platform-web-configration ---

[INFO] Using 'UTF-8' encodingto copy filtered resources.

[INFO] Copying 0 resource

[INFO]

[INFO] ---maven-compiler-plugin:3.1:testCompile (default-testCompile) @platform-web-configration ---

[INFO] Nothing to compile - allclasses are up to date

[INFO]

[INFO] ---maven-surefire-plugin:2.12.4:test (default-test) @ platform-web-configration---

[INFO]

[INFO] ---maven-jar-plugin:2.4:jar (default-jar) @ platform-web-configration ---

[INFO] Building jar: D:\Workspaces8.6\platform\platform-web-parent\platform-web-configration\target\platform-web-configration-0.0.1-SNAPSHOT.jar

[INFO]

[INFO] ---maven-install-plugin:2.4:install (default-install) @ platform-web-configration---

[INFO] InstallingD:\Workspaces8.6\platform\platform-web-parent\platform-web-configration\target\platform-web-configration-0.0.1-SNAPSHOT.jartoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-web-configration\0.0.1-SNAPSHOT\platform-web-configration-0.0.1-SNAPSHOT.jar

[INFO] InstallingD:\Workspaces8.6\platform\platform-web-parent\platform-web-configration\pom.xmltoC:\Users\jiancheng\.m2\repository\com\chenrui\platform\platform-web-configration\0.0.1-SNAPSHOT\platform-web-configration-0.0.1-SNAPSHOT.pom

[INFO] ------------------------------------------------------------------------

[INFO] Reactor Summary:

[INFO]

[INFO] Intergrated Platform............................... SUCCESS [ 0.333 s]

[INFO] platform-parent.................................... SUCCESS [ 0.020 s]

[INFO] platform-common-project............................ SUCCESS [ 0.025 s]

[INFO] platform-common.................................... SUCCESS [ 1.280 s]

[INFO] platform-system-project............................ SUCCESS [ 0.013 s]

[INFO] platform-system-dao................................ SUCCESS [ 0.051 s]

[INFO] platform-system-service............................ SUCCESS [ 0.040 s]

[INFO] platform-system-entity............................. SUCCESS [ 0.039 s]

[INFO] platform-system-utils.............................. SUCCESS [ 0.032 s]

[INFO]platform-configration-project ...................... SUCCESS [  0.020 s]

[INFO]platform-configration-dao .......................... SUCCESS [  0.057 s]

[INFO]platform-configration-service ...................... SUCCESS [  0.049 s]

[INFO]platform-configration-entity ....................... SUCCESS [  0.051 s]

[INFO]platform-configration-utils ........................ SUCCESS [  0.038 s]

[INFO]platform-webservice-project ........................ SUCCESS [  0.014 s]

[INFO] platform-webservice-solr........................... SUCCESS [ 0.020 s]

[INFO]platform-webservice-solr-client .................... SUCCESS [  0.044 s]

[INFO]platform-webservice-solr-server .................... SUCCESS [  0.038 s]

[INFO]platform-webservice-solr-pojo ...................... SUCCESS [  0.045 s]

[INFO]platform-webservice-solr-utils ..................... SUCCESS [  0.051 s]

[INFO] platform-mq-project................................ SUCCESS [ 0.008 s]

[INFO] platform-web-parent................................ SUCCESS [ 0.012 s]

[INFO] platform-web-common................................ SUCCESS [ 0.042 s]

[INFO] platform-web-system................................ SUCCESS [ 0.041 s]

[INFO]platform-web-configration .......................... SUCCESS [  0.063 s]

[INFO]------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO]------------------------------------------------------------------------

[INFO] Total time: 2.783 s

[INFO] Finished at:2014-10-10T09:59:03+08:00

[INFO] Final Memory: 15M/164M

[INFO]------------------------------------------------------------------------

 

将整个项目install后,将整个项目的所有的jar及pom存放到了本地仓库中,再次启动项目,就能够找到相应依赖的jar包了。这种方法针对多模块项目比较烦琐,可以应用“通过Tomcat直接部署运行”简单。

 

查看运行结果

 

但目前有一个问题:当模块platform-system-service中加入一个新的方法,在servlet中调用的时候,要求必须先针对platform-system-service模块 install后,才能被引用,此问题,暂未解决。替代方案,应用tomcat部署的模式。

九、         MyEclipse中m2eclipse插件其它应用

1.    查看仓库位置

在myeclipse中查看仓库的位置信息

Window –> show view -> other ,见下图

 

2.    添加依赖

 

在myeclipse中添加依赖提供了两种选项。

第一种选项是通过手动的编辑POM文件的XML内容来添加一个依赖。这种手动编辑POM文件方式的缺点是你必须知道构件的信息。好处是在你手工添加依赖并保存POM文件之后,项目的Maven依赖容器会自动更新以包含这个新的依赖。

第二种添加依赖的方式容易得多,因为你不需要知道构件的除groupId以外的信息。通过简单的在搜索框中输入信息,m2eclipse会查询仓库索引,显式在本地Maven仓库中构件的版本。这种方式更好因为它能节省大量的时间。有了m2eclipse,你不再需要中央Maven仓库中搜寻一个构件版本。

 

3.    查看依赖

 

4.    显示项目版本

Window -> preferencs ->general -> appearance -> lable Decorations -> maven version decorator

 

 

 

十、         其它

1.    安装jar到本地仓库

 有的jar包在maven中心中是不存在的,或者无法连接网络下载,我们可以直接通过命令将jar安装到本地仓库中,如将mqtt-client-0.4.0.jar文件存放到本地仓库中

 

 

C:\>mvn install:install-file-Dfile=c:\mqtt-client-0.4.0.jar -DgroupId=org.eclipse.paho-DartifactId=mqtt-client -Dversion=0.4.0 -Dpackaging=jar

 

2.    导入maven项目到eclipse

EclipsePackageExplorer中单击右键 -> Import… -> Maven –> 选中Existing Maven Projects ->单击Next –>在弹出的select rootfolder窗口中单击Browser…按钮 ->在弹出的窗口中找到刚才创建的目录并选中pom.xml文件 –>单击OK -> Finish即可将这个工程导入到Eclipse中。Maven的顶级工程已经创建完毕。

 

3.    maven项目lib下面的jar无法发布到tomcat下面

对项目右键---点击Properties,搜索选择 Deployment Assembly,点击下图右边的”Add…”按钮,

选择Java BuildPath Entries,点击Next,然后选择你的MavenDependencies,点击Finish即可。

 

 文档下载 http://download.csdn.net/detail/dahaigegege/9371829   转载分享,请注明来源,谢谢。

0 0