zoukankan      html  css  js  c++  java
  • Java_maven构建项目(多模块项目)

    在eclipse下构建maven项目,该项目由多个子模块组成。

    1.创建一个父项目

    NEW -->project-->maven-->maven Project,点击下一步,进入new maven Project的Select project name and location界面

    ,什么也不做,直接下一步到Select an Archetype界面。

    在这个界面中选择maven-Archetype-site-simple,然后选择下一步,进入选择Enter a group id for the artifact的界面

    ,在group id 和artifact id中输入你的group和artifact名称。我用的分别是A和B,选择完成。这时会在eclipse中生成一个项目,项目名是B。

    此时B的pom文件如下所示:

    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>A</groupId>  
    6.   <artifactId>B</artifactId>  
    7.   <version>0.0.1-SNAPSHOT</version>  
    8.   <packaging>pom</packaging>  
    9.   
    10.   <distributionManagement>  
    11.     <site>  
    12.       <id>website</id>  
    13.       <url>scp://webhost.company.com/www/website</url>  
    14.     </site>  
    15.   </distributionManagement>  
    16.   
    17.   <properties>  
    18.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    19.   </properties>  
    20. </project>  
    <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">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>A</groupId>
      <artifactId>B</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>pom</packaging>
    
      <distributionManagement>
        <site>
          <id>website</id>
          <url>scp://webhost.company.com/www/website</url>
        </site>
      </distributionManagement>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    </project>

    2.创建子项目

    2.1 将项目B中的src文件删除(可有可无,主要看个人需要) 2.2 选中项目B,点击右键,选择NEW -->project-->maven-->maven Module,点击下一步,在出现的界面中输入子模块的名称C,点击下一步,出现Select an Archetype界面。这时选择maven-Archetype-site-quickStart或者maven-Archetype-webapp(构建web层时使用),然后选择完成,即生成子项目C。

    这时B的pom文件就变成了这样(和上面的比只是多了个modules标签):

    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>A</groupId>  
    6.   <artifactId>B</artifactId>  
    7.   <version>0.0.1-SNAPSHOT</version>  
    8.   <packaging>pom</packaging>  
    9.   
    10.   <distributionManagement>  
    11.     <site>  
    12.       <id>website</id>  
    13.       <url>scp://webhost.company.com/www/website</url>  
    14.     </site>  
    15.   </distributionManagement>  
    16.   
    17.   <properties>  
    18.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    19.   </properties>  
    20.   <modules>  
    21.     <module>C</module>  
    22.   </modules>  
    23. </project>  
    <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">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>A</groupId>
      <artifactId>B</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>pom</packaging>
    
      <distributionManagement>
        <site>
          <id>website</id>
          <url>scp://webhost.company.com/www/website</url>
        </site>
      </distributionManagement>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <modules>
      	<module>C</module>
      </modules>
    </project>

    这时构建B的子项目完成,构建其他的子项目和此类似。

    在构建第二个子项目D时可能在B中没有及时出现,这时只要把B项目刷新下就可以了。

    ps:

    其实在构建多模块的项目时,在选择父项目的类型时是可以选择任意的类型。选择项目类型的界面如下:

    对于这些非常规类型的项目,如果想要成为父项目,需要做如下一些改动:

    1.将pom.xml文件中的<packaging>jar</packaging>改为<packaging>pom</packaging>,若不换为pom则在打包的时候父项目会产生一个target文件;如果没有<packaging>pom</packaging>的可以在<version>0.0.1-SNAPSHOT</version>后面添加上这句话即可。

    2.删除除pom.xml外的所有文件,其中JRE System Library是不能直接删除的,需要选择中,并单击右键Bulid Path-->Remove from bilud path即可移除。

    这时的父项目就显得很干净整洁了。

    其实在普通的项目上是不允许构建子模块的,能否在一个项目下创建子模块,主要取决于是否有<packaging>pom</packaging>这个配置。如果有这个配置则任何项目都可以创建子模块,硬要这样创建的话整个项目会变的不伦不类。看来maven在判断一个项目是否可以创建子模块其实是取决于这个配置的。

  • 相关阅读:
    C# Math.Round的枚举参数
    Literature Review: Incremental Segment-Based Localization in 3D Point Clouds
    Literature Review: Benchmarking 6DOF Outdoor Visual Localization in Changing Conditions
    Literature Review: Improving Image-Based Localization by Active Correspondence Search
    Literature Review: 基于稀疏直接法的建图
    论文阅读: 基于SLAM的使用GPS和鱼眼相机第Integrity Monitoring
    论文阅读: v-charge项目: 电动车的自动泊车和充电
    论文阅读: Infrastructure-Based Calibration of a Multi-Camera Rig
    论文阅读: Building a 3-D Line-Based Map Using Stereo SLAM
    论文阅读: VITAMIN-E: Extremely Dense Feature Points
  • 原文地址:https://www.cnblogs.com/MarchThree/p/4677662.html
Copyright © 2011-2022 走看看