zoukankan      html  css  js  c++  java
  • Maven多模块项目新建技巧-解决公共项目install之后可以在单独模块中直接编译

    说明:如果按照这种方式http://www.cnblogs.com/EasonJim/p/8303878.html,且按照常规的install方式在子项目中编译项目,那么需要先install一下parent项目,最后才能编译子项目。这种方式其实不太好,每次都intall一大堆项目,所以为了解决这种重的方式,可以只install公共模块,然后使其单独能编译子项目。

    解决方式:

    1、在常规新建的多模块项目(http://www.cnblogs.com/EasonJim/p/6863987.html)时,把公共模块的pom的parent节点去除即可。比如样例工程bus-core-api下的pom如下:

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.jsoft.test</groupId>
        <artifactId>testproject</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <groupId>com.jsoft.test</groupId>
      <artifactId>bus-core-api</artifactId>
      <version>1.0-SNAPSHOT</version>
      <name>bus-core-api</name>
      <url>http://maven.apache.org</url>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>

    去除了parent节点后是这样的:

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.jsoft.test</groupId>
      <artifactId>bus-core-api</artifactId>
      <version>1.0-SNAPSHOT</version>
      <name>bus-core-api</name>
      <url>http://maven.apache.org</url>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>

    那么这样操作之后,直接install了bus-core-api之后就可以单独编译app-desktop-ui等项目。

    注意:子模块去除了parent节点之后,随着而来的特性也会丢失,比如在父项目定义的配置项,那么也不能使用,比如父项目增加的包,那么在子项目也不能继承使用,只能单独自己引入。

    测试工程:https://github.com/easonjim/5_java_example/tree/master/maventest/test10/testproject

  • 相关阅读:
    SOJ 2785_Binary Partitions
    Codeforces Round #328 (Div. 2)
    C++ fill 和memset
    SOJ 2749_The Fewest Coins
    Codeforces Round #327 (Div. 2)
    TYVJ P1013 找啊找啊找GF Label:动态规划
    TYVJ 1014 乘法游戏
    TYVJ 1011 NOIP 2008&&NOIP 2000 传纸条&&方格取数 Label:多线程dp
    错误集合
    TYVJ P1038/P1039 忠诚 标签:线段树
  • 原文地址:https://www.cnblogs.com/EasonJim/p/8303917.html
Copyright © 2011-2022 走看看