运行多模块Maven项目 [英] Run a multi-module Maven project

查看:83
本文介绍了运行多模块Maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个基本问题,我对maven多模块结构并不熟悉。说,我有一个Web应用程序。我想将一些模块连接到它(一些服务)。我是否需要创建一个Web应用程序,只是其中一个模块,依赖于其他模块,然后运行它?起初我以为我可以运行整个项目,但是这个选项在我的IDE中变得不活跃(我现在正在使用NetBeans),这让我觉得我应该运行类似主模块(在这种情况下是一个Web应用程序) )。是这样吗?在此先感谢。

This is a basic question, I'm just not really familiar with maven multi-module structures. Say, I have a web application. And I want to connect some modules to it (some services). Do I need to make a web app just one of the modules, dependent from some others, and then run it? At first I thought I could run the whole project, but this option turns out to be inactive in my IDE (I'm using NetBeans now), which made me think I should run something like a main module (a web app in this case). Is it so? Thanks in advance.

推荐答案

如果你有一个多模块项目,你需要一个像下面这样的结构,它也将由文件夹结构。

If you have a multi-module project you need a structure like the following which will also be represented by the folder structure as well.

+-- root (pom.xml)
     +--- module-1
     +--- module-2
     +--- module-war 

根模块包含如下内容:

<project ..>

  <groupId>com.test.project</groupId>
  <artifactId>parent</artifactId>
  <version>1.0-SNAPSHOT</version>

  <modules>
    <module>module-1</module>
    <module>module-2</module>
    <module>module-war</module>
  </modules>

</project>

在模块-1中你的pom应如下所示:

In the module-1 your pom should look like this:

<project ..>
  <parent>
    <groupId>com.test.project</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>module-1</artifactId>

  dependencies for the module

</project>

在模块-2中它看起来或多或少相同......在war模块中它看起来像:

in module-2 it look more or less the same..and in the war module it looks like:

<project ..>
  <parent>
    <groupId>com.test.project</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <packaging>war</packaging>
  <artifactId>module-war</artifactId>

  dependencies for the module

</project>

如果模块之间存在依赖关系,例如模块-1取决于模块-2,它看起来像在模块1中跟随:

If you have dependencies between the modules for example module-1 depends on module-2 it looks like the following in module-1:

<project ..>
  <parent>
    <groupId>com.test.project</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>module-1</artifactId>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>module-2</artifactId>
      <version>{project.version}</version>
    </dependency>

    ..other dependencies..

  </dependencies>

</project>

要构建和打包项目,您将转到父文件夹,只需

To build and package your project you will go to parent folder and do simply a

mvn clean package

这篇关于运行多模块Maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆