Maven:包装复制文件夹后,将粘贴Web-Inf复制到根中



我有一个类似的项目:

TestArt
-----------index.jsp
-----------pom.xml
-----------src
--------------main
------------------java/com/web/LoginServlet.java
------------------webapp/WEB-INF/classes/com/web/LoginServlet.class
-----------target
-----------------testproject-1.0-SNAPSHOT.war
-----------------testproject-1.0-SNAPSHOT.war.original
-----------------testproject-1.0-SNAPSHOT
----------------------------------META-INF
----------------------------------WEB-INF
---------------------------------------classes/com/web/LoginServlet.class
---------------------------------------lib (here are all the jars)

pom.xml 喜欢这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.util</groupId>
    <artifactId>testproject</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Test Project</name>
    <url>https://test.com</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>
    <dependencies>
        ...
    </dependencies>
    <properties>
        <java.version>1.7</java.version>
        <start-class>com.web.LoginServlet</start-class>
    </properties>
    <build>
        <outputDirectory>${basedir}srcmainwebappWEB-INFclasses</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals><goal>copy</goal></goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.github.jsimone</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>8.0.30.2</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
            </plugin>
            <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
        <defaultGoal>install</defaultGoal>
    </build>
</project>

我运行 MVN软件包它创建 Meta-Inf Web-Inf Folder root/target 文件夹和位置 .war 中的文件。

我希望Maven还将 Web-Inf 文件夹从 target 复制到root( testart )中。有什么方法可以实现吗?

我真的建议您花时间解决原始问题,但是如果您想要:

使用maven antrun插件将文件夹从一个地方复制到另一个地方,如下所述:

https://stackoverflow.com/a/694175/927493

此处解释了ANT中复制命令的详细信息:

https://ant.apache.org/manual/tasks/copy.html

无法用Ant弄清楚,所以我使用了此答案。就我而言,看起来像这样:

  <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>copy-resources</id>
                <!-- here the phase you need -->
                <phase>validate</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/WEB-INF</outputDirectory>
                    <resources>
                        <resource>
                            <directory>target/testproject-1.0-SNAPSHOT/WEB-INF</directory>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
  </plugin>

edit :此插件复制一个逐一粘贴文件,而不是取一个文件夹,然后将其与所有文件一起复制粘贴。这会导致班级和目录之间的链接断开,而且似乎没有任何作用。目前,我正在使用batch脚本:

xcopy "C:...Tomcat 8.5webappsTestArttargettestproject-1.0-SNAPSHOTWEB-INF" "C:...Tomcat 8.5webappsTestArtWEB-INF" /E /Y

使用此答案的Maven插件:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>sign</id>
                    <phase>package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <exec executable="${basedir}copy.bat">
                            </exec>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我设法取得了理想的结果。

但是,如果纯Maven中有解决方案可以一次复制一个目录,我很想听听它们。

相关内容

  • 没有找到相关文章

最新更新