如何覆盖maven-war-plugin源目录

问题描述 投票:4回答:3

我有旧的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
3个回答
1
投票

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


1
投票

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>

0
投票

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

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <warSourceDirectory>old/project/source</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>
© www.soinside.com 2019 - 2024. All rights reserved.