如何使用Maven Resources Plugin解压缩从本地目录复制的war文件?

时间:2016-07-05 10:44:24

标签: maven tomcat cas

我正在尝试将CAS服务器与Spring应用程序集成。 (我已在本地配置CAS,在我的Tomcat服务器中,它正常工作)。使用Maven Resources Plugin我将cas.war文件复制到我的Web应用程序的目标文件夹中。但我需要解压缩cas.war文件才能覆盖我修改过的一些文件。

如何解压缩使用Maven Resources Plugin复制的war文件?

这是我的pom.xml

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warName>cas</warName>
                <webResources>
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                        <includes>
                            <include>**/web.xml</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <webApp>
                    <contextPath>/cas</contextPath>
                </webApp>
            </configuration>
        </plugin>

        <!--Copy plugin-->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.1</version>
            <executions>

                <!--copy cas.war file-->
                <execution>
                    <id>copy-initial-cas.war</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${basedir}/target/cas</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${CAS.LOCATION}/target</directory>
                                <includes>
                                    <include>cas.war</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>


                <!--copying deployerConfigContext file-->
                <execution>
                    <id>copy-deployerConfigContext</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${basedir}/target/cas/WEB-INF</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/resources</directory>
                                <includes>
                                    <include>deployerConfigContext.xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>


                <!--copying web.xml file-->
                <execution>
                    <id>copy-web.xml</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${basedir}/target/cas/WEB-INF</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/resources</directory>
                                <includes>
                                    <include>web.xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>


                <!--copying casdatabase.properties file-->
                <execution>
                    <id>copy-casdatabase.properties</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/cas/WEB-INF</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/resources</directory>
                                <includes>
                                    <include>casdatabase.properties</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!--unpacking plugin-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>unzip-war</id>
                    <phase>install</phase>
                    <configuration>
                        <tasks>
                            <echo message="unpack cas.war" />
                            <unzip src="${basedir}/target/cas/cas.war" dest="${basedir}/target/cas" overwrite="true"/>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

1 个答案:

答案 0 :(得分:0)

如果你想覆盖战争中的资源,你应该使用maven overlay方法。