多模块Maven项目和码头:运行 [英] Multi-module Maven project and jetty:run

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

问题描述

我试图将Maven WAR项目分成两个模块,以便可以使用命令行工具构建单独的JAR文件.结果具有以下结构:

I'm trying to split a Maven WAR project into two modules, so that I can build a separate JAR file with command line tools. The result has the following structure:

  • pom.xml(包装pom,有两个模块)
  • project-jar/
    • pom.xml(包装jar)
    • pom.xml (packaging pom, has two modules)
    • project-jar/
      • pom.xml (packaging jar)
      • pom.xml(包装war,取决于project-jar)
      • pom.xml (packaging war, depends on project-jar)

      如果我从根目录运行mvn命令,则一切正常.我想继续使用mvn jetty:run,但是为此,我需要在WAR子项目中执行命令.如果这样做,将无法找到project-jar子项目,因此它将无法运行.即使mvn jetty:run-wartarget目录中具有完全组装的WAR文件,也会失败,因为它首先尝试构建"项目.我只能通过将project-jar安装到本地Maven存储库中来使其工作,这不是很好.

      If I run mvn commands from the root, everything works fine. I'd like to keep using mvn jetty:run, but for that I need to execute the command in the WAR subproject. If I do that, fails to find the project-jar subproject, so it won't run. Even mvn jetty:run-war with a completely assembled WAR file in the target directory fails, because it first tries to "build" the project. I've only managed to make it work by installing project-jar into the local Maven repository, which isn't very nice.

      是否可以在多模块Maven配置中使用Jetty插件?

      Is there a way to use the Jetty plugin in a multi-module Maven configuration?

      推荐答案

      没有神奇的解决方案,我知道的唯一解决方案是有点骇人听闻,它依赖于您可以用来声明额外的类目录的extraClasspath元素,相对地.像这样(来自 JETTY-662 ):

      There is no magical solution and the only one I know is a bit hacky and rely on the extraClasspath element that you can use to declare extra class directories, relatively. Like this (from JETTY-662):

      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>7.0.1.v20091125</version>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <webAppConfig>
            <contextPath>/my-context</contextPath>
            <extraClasspath>target/classes;../my-jar-dependency/target/classes</extraClasspath>
          </webAppConfig>
          <scanTargets>
            <scanTarget>../my-jar-dependency/target/classes</scanTarget>
          </scanTargets>
        </configuration>
      </plugin>
      

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

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