代码之家  ›  专栏  ›  技术社区  ›  LukáÅ¡ Lalinský

多模块Maven项目和码头:运行

  •  34
  • LukáÅ¡ Lalinský  · 技术社区  · 14 年前

    • pom.xml pom ,有两个模块)
    • project-jar/
      • (包装) jar )
    • project-war/
      • pom.xml文件 war ,取决于 project-jar

    如果我跑了 mvn 从根本上说,一切正常。我想继续用 mvn jetty:run 子项目,所以它不会运行。甚至 mvn jetty:run-war 一个完整的战争档案 target 目录失败,因为它首先尝试“构建”项目。我只是通过安装 jar项目 进入本地Maven存储库,这不是很好。

    5 回复  |  直到 14 年前
        1
  •  11
  •   Pascal Thivent    14 年前

    extraClasspath 元素,您可以使用它来声明额外的类目录。像这样(从 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>
    
        2
  •  29
  •   Patrick    13 年前

    在war模块中创建一个概要文件( project-war run 明确目标。现在,当maven在启用该概要文件的情况下从顶层项目运行时,它将调用码头:快跑具有姐妹模块依赖关系解析(在从顶级项目执行maven命令时是正常的)。

    示例配置,当放置在pom.xml文件web模块的( ),安排码头:跑到执行期间 test 阶段。(你可以选择另一个阶段,但一定要在 compile

    从顶层运行: mvn test -Pjetty-run mvn test -DskipTests=true -Pjetty-run . 这将根据需要编译依赖项并使它们可用,但调用码头:运行范围正确的模块。

    <profiles>
      ...
      <!-- With this profile, jetty will run during the "test" phase -->
      <profile>
        <id>jetty-run</id>
        <build>
          <plugins>
            <plugin>
              <groupId>org.mortbay.jetty</groupId>
              <artifactId>jetty-maven-plugin</artifactId>
              <version>7.1.6.v20100715</version>
              <configuration>
                ...
                <webAppSourceDirectory>
                  ${project.build.directory}/${project.build.finalName}
                </webAppSourceDirectory>
                ...
              </configuration>
              <executions>
                <execution>
                  <id>jetty-run</id>
                  <phase>test</phase>
                  <goals>
                    <goal>run</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </profile>
    ...
    </profiles>
    
        3
  •  1
  •   Jaime Hablutzel    14 年前

    在jetty配置工作中使用extraClasspath。。。但是由于某些原因,如果依赖jar(来自其他模块)过时了,那么有些东西就不能正常工作。

        4
  •  1
  •   Serge    9 年前

    将jetty插件添加到根pom并配置指向所需war的contextHandler。在一个有多个jar模块和两个overlay war的项目中,这对我来说很有用。

    <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.3.0.M2</version>
    <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
            <contextHandlers>
                <contextHandler
                    implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                    <war>${project.basedir}/project-war/target/project-war-${project.version}.war</war>
                    <contextPath>/</contextPath>
                </contextHandler>
            </contextHandlers>
        </configuration>
    </plugin>
    

    http://eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#running-more-than-one-webapp

        5
  •  0
  •   Andrew Grover    9 年前

    我知道您要求插件配置,但您可以在maven命令中定义项目:

    $ mvn jetty:run --projects project-war
    
        6
  •  0
  •   simon04 Jonathan A. Marshall    4 年前

    documentation for jetty:run 注意到

    从码头9.4.7开始,使用时码头:磨合在多模块构建中,不再需要先构建构成webapp依赖项的每个模块。因此,如果您的webapp依赖于项目中的其他模块,并且它们同时存在于reactor中,那么jetty将使用它们编译的类,而不是本地maven存储库中的jar文件。

    jetty-maven-plugin 到Maven根项目并运行 mvn jetty:run