【问题标题】:how to override maven-war-plugin source directory如何覆盖 maven-war-plugin 源目录
【发布时间】:2013-10-25 22:21:51
【问题描述】:

我有旧的 Web 应用程序项目。然后我添加了pom.xml,并添加了maven-war-plugin。在旧项目中,源位于"Java Resources/src"directory。

在我的 maven-war 插件中,我尝试像这样覆盖默认源目录,但不起作用。

在编译期间我看到: `

[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ webproj ---
[INFO] No sources to compile
[INFO]

`

我的pom.xml

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>exploded</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <webXml>WebContent\WEB-INF\web.xml</webXml>    
                <webappDirectory>WebContent</webappDirectory>
                <source>${project.basedir}\src</source>         
                <target>${maven.compiler.target}</target>
                <encoding>utf-8</encoding>
            </configuration>
        </plugin>

【问题讨论】:

    标签: java web-applications maven-2


    【解决方案1】:

    您可以在maven-war-plugin 配置中指定warSourceDirectory

    <project>
        ...
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <warSourceDirectory>old/project/source</warSourceDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        ...
    </project>
    

    【讨论】:

      【解决方案2】:

      Maven-war-plugin 使用项目源文件夹来覆盖您必须放入 pom 中的位置,如下所示:

      <build>
      
          <sourceDirectory>/Java Resources/src</sourceDirectory>
          <plugins>
              ...
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>build-helper-maven-plugin</artifactId>
                  <version>${version.build-helper-maven-plugin}</version>
                  <executions>
                      <execution>
                          <phase>generate-sources</phase>
                          <goals>
                              <goal>add-source</goal>
                          </goals>
                          <configuration>
                              <sources>
                                  <source>social/src/main/java</source>
                              </sources>
                          </configuration>
                      </execution>
                  </executions>
              ...
          </plugins>
      <build>
      

      【讨论】:

      • 当我尝试发动战争时对我不起作用:爆炸。该插件尝试在默认源目录中获取源代码
      • @herau 你覆盖了sourceDirectory?,它是一个maven 属性,不是maven-war-plugin 选项,这个插件只有在你需要更多目录时才有用。
      【解决方案3】:

      如果你打算迁移到 Maven,我建议你关注Maven Standard Directory Layout。因此,您应该将源文件移动到 src/main/java,将 .properties 文件等静态资源移动到 src/main/resources,并将 CSS 和 JavaScript 文件等 webapp 资源移动到 src/main/webapp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-20
        • 2016-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-18
        相关资源
        最近更新 更多