java要多思考下

          成長^_^

             ::  :: 新隨筆 ::  ::  :: 管理 ::
            33 隨筆 :: 0 文章 :: 19 評(píng)論 :: 0 Trackbacks

          公告

                     專注于互聯(lián)網(wǎng)技術(shù),興趣愛好廣泛,邏輯思維甚好,數(shù)學(xué)專業(yè)出生。記錄生活,記錄工作。工作是快樂時(shí),生活就是幸福;工作是義務(wù)時(shí),生活就會(huì)痛苦O(∩_∩)O~

          留言簿(2)

          隨筆分類(36)

          最新隨筆

          最新評(píng)論

          1、按項(xiàng)目需求拆分模塊,配置maven項(xiàng)目結(jié)構(gòu)
          2、將項(xiàng)目拆分為一個(gè)java項(xiàng)目common,與多個(gè)web項(xiàng)目,建立他們之間的依賴關(guān)系
          項(xiàng)目結(jié)構(gòu)如下:
              demo--|
                     demo-common--|
                      src/main/java
                      src/main/resource
                      pom-common.xml
                     demo-web-----|
                      src/main/java
                      src/main/resource
                      src/main/webapp
                      pom-web.xml
                     pom.xml
          3、編寫pom文件,配置項(xiàng)目依賴環(huán)境
          3.1、pom.xml

           1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
           3     <modelVersion>4.0.0</modelVersion>
           5     <name>demo</name> 
           7     <artifactId>demo</artifactId>
           8     <groupId>com.demo</groupId>
           9     <version>1.0.0-SNAPSHOT</version>
          10     <packaging>pom</packaging>
          11     
          12     <modules>
          13         <module>demo-common/trunk</module>
          14         <module>demo-web/trunk</module>
          15     </modules>
          ........
          3.2、pom-common.xml

          1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          2         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          3         <modelVersion>4.0.0</modelVersion>
          4 
          5         <groupId>com.demo</groupId>
          6         <artifactId>demo-common</artifactId>
          7         <packaging>jar</packaging>
          8         <version>1.0.0-SNAPSHOT</version>
          9     
          3.3、pom-web.xml

            1 <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/xsd/maven-4.0.0.xsd">
            2     <modelVersion>4.0.0</modelVersion>
            3     <artifactId>demo-web</artifactId>
            4     <packaging>war</packaging>
            5     <version>3.0</version>
            6 
            7     <parent>  
            8         <artifactId>demo</artifactId>  
            9         <groupId>com.demo</groupId> 
           10         <version>1.0.0-SNAPSHOT</version>  
           11     </parent>  
           12 
           13   <properties>
           14     <demo.common.version>3.0.0-SNAPSHOT</demo.common.version>
           15   </properties>
           16     
           17  <build>
           31         <plugins>
           32             <plugin>
           33                 <groupId>org.apache.maven.plugins</groupId>
           34                 <artifactId>maven-eclipse-plugin</artifactId>
           35                 <version>2.8</version>
           36                 <configuration>
           37                     <wtpversion>2.0</wtpversion>
           38                     <sourceExcludes>
           39                         <sourceExclude>**/.svn/</sourceExclude>
           40                     </sourceExcludes>
           41                     <downloadSources>true</downloadSources>
           42                     <outputDirectory>
           43                         src/main/webapp/WEB-INF/classes
           44                     </outputDirectory>
           45                 </configuration>
           46             </plugin>
           47             <plugin>
           48                 <groupId>org.apache.maven.plugins</groupId>
           49                 <artifactId>maven-compiler-plugin</artifactId>
           50                 <version>2.3.2</version>
           51                 <configuration>
           52                     <source>1.6</source>
           53                     <target>1.6</target>
           54                     <encoding>UTF-8</encoding>
           55                 </configuration>
           56             </plugin>
           57             <plugin> 
           58                 <groupId>org.apache.maven.plugins</groupId> 
           59                 <artifactId>maven-resources-plugin</artifactId> 
           60                 <version>2.4</version> 
           61                 <configuration> 
           62                     <encoding>UTF-8</encoding> 
           63                 </configuration> 
           64             </plugin> 
           65             <plugin>
           66                 <groupId>org.codehaus.mojo</groupId>
           67                 <artifactId>aspectj-maven-plugin</artifactId>
           68                 <version>1.3.1</version>
           69                 <dependencies>
           70                     <dependency>
           71                         <groupId>org.aspectj</groupId>
           72                         <artifactId>aspectjrt</artifactId>
           73                         <version>1.6.10</version>
           74                     </dependency>
           75                     <dependency>
           76                         <groupId>org.aspectj</groupId>
           77                         <artifactId>aspectjtools</artifactId>
           78                         <version>1.6.10</version>
           79                     </dependency>
           80                 </dependencies>
           81                 <configuration>
           82                     <source>1.6</source>
           83                     <target>1.6</target>
           84                     <XnoInline>true</XnoInline>
           85                     <showWeaveInfo>true</showWeaveInfo>
           86                 </configuration>
           96             </plugin>
           97         </plugins>
           98  </build>
           99 
          100   <dependencies>
          101     <dependency>  
          102             <groupId>com.demo</groupId>  
          103             <artifactId>demo-common</artifactId>  
          104             <version>${demo.common.version}</version>  
          105     </dependency> 
          106     
          4、這時(shí),在demo根目錄下執(zhí)行mvn package -Dmaven.test.skip=true,執(zhí)行成功表明配置有效
          5、在demo根目錄下執(zhí)行 mvn eclipse:eclipse 生成eclipse項(xiàng)目環(huán)境
          6、在eclipse中使用import-->maven導(dǎo)入maven項(xiàng)目

          7、這時(shí)會(huì)看到eclipse里產(chǎn)生三個(gè)項(xiàng)目,一個(gè)是demo,一個(gè)是demo-common,一個(gè)是demo-web,其中demo-web是web項(xiàng)目

          技術(shù)文章收藏站點(diǎn)
          posted on 2011-12-26 19:01 java要多思考下 閱讀(4581) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 洱源县| 东阳市| 资溪县| 廉江市| 高陵县| 连云港市| 文安县| 名山县| 融水| 温州市| 西贡区| 阿坝| 远安县| 永兴县| 建始县| 理塘县| 河源市| 遵义县| 沂水县| 郸城县| 东莞市| 依安县| 买车| 托克逊县| 全州县| 蛟河市| 晋城| 大竹县| 射阳县| 乌鲁木齐市| 阳东县| 布尔津县| 阳朔县| 秦安县| 尚志市| 仙桃市| 阿坝| 久治县| 茌平县| 龙泉市| 安仁县|