<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我的漫漫程序之旅

    專注于JavaWeb開發
    隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
    數據加載中……

    使用MyEclipse構建MAVEN項目

    這里用的是MyEclpise的自帶的MAVEN插件。
    Maven最好配置成你自己安裝的那個,MyEclipse自帶會有些許Bug。


    用nexus代理Maven的中央倉庫,setting.xml的配置文件修改內容如下:
    <mirrors>
         <mirror>
              <id>nexus</id>
              <mirrorOf>*</mirrorOf>
              <name>Nexus Mirror</name>
              <url>http://localhost:8081/nexus/content/groups/public</url>
         </mirror>
      </mirrors>
      
      <profiles>
         <profile>
          <id>nexus</id>
          <repositories>
            <repository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
          </repositories>
         <pluginRepositories>
            <pluginRepository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
          </pluginRepositories>
        </profile>
      </profiles>
      <activeProfiles>
        <activeProfile>nexus</activeProfile>
      </activeProfiles>
    http://localhost:8081/nexus/content/groups/public 是倉庫組的地址。
    打下MyEclipse新建工程的界面,選擇Maven下的Maven Project,打開如下圖的向導:

    這里我們要選中create a simple project。
    點擊下一步,填寫GAV相關內容。

    點擊完成后,我們就已經成功創建了一個Maven project了。
    工程的默認目錄結構如下:


    所有的Java源文件都要寫在src/main/java目錄下,所有的測試類都要寫在src/test/java下面,這是Maven的默認值。
    此時,pom.xml里只有默認的屬性
    <project xmlns="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.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.test</groupId>
      <artifactId>test</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </project>
    這是最精簡的pom.xml了。
    這時我們加入junit的支持,新建一個測試類。
    在項目上右鍵Maven-Add Dependency,顯示如下界面:

    輸入junit加入測試支持類庫。
    在src/test/java下新建一個測試類如下:
    package com;
    import org.junit.Test;
    public class TestRun
    {
    @Test
    public void testA()
    {
    System.out.println("test a method ");
    }
    @Test
    public void testB()
    {
    System.out.println("test b method ");
    }
    }
    右鍵Run As ----- Maven test,進行測試,顯示結果如下:



    [INFO] Scanning for projects
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building test 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ test ---
    [debug] execute contextualize
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ test ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ test ---
    [debug] execute contextualize
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ test ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ test ---
    [INFO] Surefire report directory: D:\workspace\test\target\surefire-reports

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.TestRun
    test a method 
    test b method 
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.071 sec

    Results :

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

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.847s
    [INFO] Finished at: Tue Sep 11 14:20:59 CST 2012
    [INFO] Final Memory: 3M/6M
    [INFO] ------------------------------------------------------------------------
    ok,一個基本的maven項目已經構建完成。我們還可以將現存的java項目利用myclipse方便的轉換成maven project,此部分內容我們在下一節里討論。

    posted on 2012-09-11 14:25 々上善若水々 閱讀(67507) 評論(9)  編輯  收藏 所屬分類: Maven

    評論

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    看你寫的挺好的 ,但是為什么沒有圖片呀???求圖關注中
    2013-02-25 20:35 | 731982341@qq.com

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    UP主,你的圖片掛了。求補
    教程不錯=.=
    2013-03-21 09:48 | Mr.zhan9

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    @Mr.zhan9
    已修復
    2013-03-26 17:26 | 々上善若水々

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    MYECLIPSE的版本?
    2013-09-17 19:38 | REDJACK

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    不錯,寫的很好。
    2013-12-11 09:32 | 不凡

    # re: 使用MyEclipse構建MAVEN項目[未登錄]  回復  更多評論   

    2015-04-18 14:15 | w

    # re: 使用MyEclipse構建MAVEN項目[未登錄]  回復  更多評論   

    用nexus代理Maven的中央倉庫,setting.xml的配置文件修改內容如下:

    這里的setting.xml 必須這樣嗎? 可以默認的吧
    2015-10-13 10:40 | 1

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    nexus需要安裝嗎?
    2016-02-26 11:50 | Jagtu

    # re: 使用MyEclipse構建MAVEN項目  回復  更多評論   

    <profile>
    <id>nexus</id>
    <repositories>
    <repository>
    <id>central</id>
    <url>http://central</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>central</id>
    <url>http://central</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
    </pluginRepositories>
    </profile>


    這一塊去掉了貌似也沒什么問題
    2016-08-29 15:08 | 龍平

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 日韩在线视频播放免费视频完整版| 亚洲一区二区三区在线播放| 91亚洲国产成人精品下载| WWW免费视频在线观看播放| 女人18毛片a级毛片免费| 亚洲综合一区二区三区四区五区| 成人免费午夜在线观看| 亚洲一卡2卡3卡4卡5卡6卡| 成全视频免费高清| 亚洲人成综合网站7777香蕉| 日韩精品无码区免费专区| 亚洲欧美乱色情图片| 四虎影视永久免费观看网址 | 深夜国产福利99亚洲视频| 国产精品亚洲а∨天堂2021| 内射无码专区久久亚洲| 四虎精品成人免费视频| 在线亚洲午夜理论AV大片| 国内精品久久久久影院免费| 亚洲视屏在线观看| 嫩草影院在线免费观看| 杨幂最新免费特级毛片| 在线A亚洲老鸭窝天堂| 久草免费手机视频| 亚洲一卡二卡三卡| 免费一级成人毛片| 国产精品免费福利久久| 亚洲一级毛片免费看| 免费一级肉体全黄毛片| 久草福利资源网站免费| 亚洲а∨天堂久久精品9966 | 久久www免费人成看国产片| 亚洲成在人天堂一区二区| 久久精品免费一区二区喷潮| 羞羞视频网站免费入口| 日韩精品一区二区亚洲AV观看| 午夜视频免费观看| 精品一区二区三区免费| 亚洲Aⅴ在线无码播放毛片一线天 亚洲avav天堂av在线网毛片 | 日韩国产精品亚洲а∨天堂免| 亚洲日韩中文无码久久|