为什么 maven-war-plugin 不打包我的文件



我不知道为什么,但maven-war-plugin停止将我的文件移动到WEB-INF/config。这就是我使用插件的方式:

<profiles>
    <profile>       
        <id>default-profile</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>   
        <build>
            <pluginManagement> 
                <plugins>   
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.6</version>
                        <configuration>
                            <webResources>
                                <resource>
                                    <directory>${basedir}/src/main/assembly/${package-mode}/config</directory>
                                    <filtering>true</filtering>
                                    <targetPath>WEB-INF/config</targetPath>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>  
                </plugins>
            </pluginManagement>
        </build>    
    </profile>
</profiles>

:我能做些什么来再次打破它?它终于奏效了,现在不再奏效了。

这是我运行服务器的方式:

mvn tomcat7:run-war -Denv=dev -Dpackage-mode=dev -DskipTests

WAR 文件被构建和打包,但来自src/main/assembly/dev/config的文件根本不存在。

根据您的问题运行下面的最小pom:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sample</groupId>
    <artifactId>web-sample</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <profiles>
        <profile>
            <id>default-profile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-war-plugin</artifactId>
                            <version>2.6</version>
                            <configuration>
                                <webResources>
                                    <resource>
                                        <directory>${basedir}/src/main/assembly/${package-mode}/config</directory>
                                        <filtering>true</filtering>
                                        <targetPath>WEB-INF/config</targetPath>
                                    </resource>
                                </webResources>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.tomcat.maven</groupId>
                            <artifactId>tomcat7-maven-plugin</artifactId>
                            <version>2.0</version>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
</project>

并按如下方式执行 Maven:

mvn tomcat7:run-war -Dpackage-mode=dev

文件被相应地复制,正如构建日志所指定的那样:

[INFO] --- maven-war-plugin:2.6:war (default-war) @ web-sample ---   
[INFO] Packaging webapp   
[INFO] Assembling webapp [web-sample] in [C:Developmentworkspace-marsweb-sampletargetweb-sample]   
[INFO] Processing war project   
[INFO] Copying webapp webResources [C:Developmentworkspace-marsweb-sample/src/main/assembly/dev/config] to [C:Developmentworkspace-marsweb-sampletargetweb-sample]   
[INFO] Copying webapp resources [C:Developmentworkspace-marsweb-samplesrcmainwebapp]   
[INFO] Webapp assembled in [106 msecs]   
[INFO] Building war: C:Developmentworkspace-marsweb-sampletargetweb-sample.war   
[INFO]     
[INFO] <<< tomcat7-maven-plugin:2.0:run-war (default-cli) < package @ web-sample <<<   

因此,错误在您的项目或POM配置中的其他位置。

我建议运行一个

mvn clean

然后重试。此外,要运行

mvn clean package

并检查文件是否被复制,无论 tomcat7 插件执行如何。

最新更新