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}\src\main\webapp\WEB-INF\classes</outputDirectory>


        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>


在我运行mvn package后,它会在根/目标文件夹中创建META-INF和WEB-INF文件夹,并将.war文件放在那里。


打包完成后,我希望 Maven 也将WEB-INF文件夹从目标复制到根目录(TestArt)。有没有办法实现它?


蝴蝶刀刀
浏览 349回答 1
1回答

慕姐8265434

无法弄清楚Ant,所以我使用了这个答案。就我而言,它看起来像这样:&nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-resources-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.6</version>&nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>copy-resources</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- here the phase you need -->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>validate</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>copy-resources</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <outputDirectory>${basedir}/WEB-INF</outputDirectory>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <resources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <resource>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <directory>target/testproject-1.0-SNAPSHOT/WEB-INF</directory>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <filtering>true</filtering>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </resource>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </resources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; </plugin>编辑:这个插件复制一个一个地粘贴文件,而不是使用一个文件夹并将其与所有文件一起复制粘贴一次。这会导致类和目录之间的链接断开,并且似乎没有任何效果。现在,我正在使用batch脚本:xcopy "C:\...\Tomcat 8.5\webapps\TestArt\target\testproject-1.0-SNAPSHOT\WEB-INF" "C:\...\Tomcat 8.5\webapps\TestArt\WEB-INF\" /E /Y使用这个答案的Maven 插件:&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-antrun-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>sign</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>package</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>run</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tasks>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exec executable="${basedir}\copy.bat">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exec>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tasks>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>我设法达到了预期的结果。但是,如果纯 Maven 中有可以一次性复制目录的解决方案,我很想听听。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java