4

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

在我的 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>
4

3 回答 3

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>
于 2013-10-17T12:54:39.800 回答
1

如果您打算迁移到 Maven,我建议您遵循Maven 标准目录布局。因此,您应该将源文件移动到src/main/java.properties 文件等静态资源src/main/resources,并将 CSS 和 JavaScript 文件等 webapp 资源移动到src/main/webapp.

于 2013-10-17T13:42:19.523 回答
0

您可以warSourceDirectorymaven-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>
于 2019-04-24T11:41:15.830 回答