How do I add a project as a dependency of another project?

后端 未结 1 829
野趣味
野趣味 2020-11-30 22:52

There are two independent projects (myWarProject and MyEjbProject). So when I build the myWarProject I need to install the MyEjb

相关标签:
1条回答
  • 2020-11-30 23:24

    Assuming the MyEjbProject is not another Maven Project you own or want to build with maven, you could use system dependencies to link to the existing jar file of the project like so

    <project>
       ...
       <dependencies>
          <dependency>
             <groupId>yourgroup</groupId>
             <artifactId>myejbproject</artifactId>
             <version>2.0</version>
             <scope>system</scope>
             <systemPath>path/to/myejbproject.jar</systemPath>
          </dependency>
       </dependencies>
       ...
    </project>
    

    That said it is usually the better (and preferred way) to install the package to the repository either by making it a maven project and building it or installing it the way you already seem to do.


    If they are, however, dependent on each other, you can always create a separate parent project (has to be a "pom" project) declaring the two other projects as its "modules". (The child projects would not have to declare the third project as their parent). As a consequence you'd get a new directory for the new parent project, where you'd also quite probably put the two independent projects like this:

    parent
    |- pom.xml
    |- MyEJBProject
    |   `- pom.xml
    `- MyWarProject
        `- pom.xml
    

    The parent project would get a "modules" section to name all the child modules. The aggregator would then use the dependencies in the child modules to actually find out the order in which the projects are to be built)

    <project>
       ...
       <artifactId>myparentproject</artifactId>
       <groupId>...</groupId>
       <version>...</version>
    
       <packaging>pom</packaging>
       ...
       <modules>
         <module>MyEJBModule</module>
         <module>MyWarModule</module>
       </modules>
       ...
    </project>
    

    That way the projects can relate to each other but (once they are installed in the local repository) still be used independently as artifacts in other projects


    Finally, if your projects are not in related directories, you might try to give them as relative modules:

    filesystem
     |- mywarproject
     |   `pom.xml
     |- myejbproject
     |   `pom.xml
     `- parent
         `pom.xml
    

    now you could just do this (worked in maven 2, just tried it):

    <!--parent-->
    <project>
      <modules>
        <module>../mywarproject</module>
        <module>../myejbproject</module>
      </modules>
    </project>
    
    0 讨论(0)
提交回复
热议问题