Maven WAR Plugin无法识别目录求助:目录存在仍报语法错误
问题根源与解决方法
你的报错核心原因是**targetPath的配置错误**:maven-war-plugin中webResources下的targetPath是相对于最终生成的WAR包根目录的相对路径,而非本地文件系统的绝对路径。你配置了${project.basedir}/app/ui这种本地绝对路径,插件会试图在WAR包内部创建带盘符的路径,Windows下这种语法完全不合法,因此触发路径错误。
修正步骤
- 将
targetPath改为WAR包内的相对路径,比如你想把dist里的内容放到WAR包的app/ui目录下,直接写:<targetPath>app/ui</targetPath> directory的配置无需修改,${project.basedir}/dist是正确的本地源目录路径,Maven会自动适配Windows和Linux的路径分隔符,不需要换成\。
修正后的完整插件配置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>${maven-war-plugin.version}</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <webResources> <resource> <!-- this is relative to the pom.xml directory --> <directory>${project.basedir}/dist</directory> <targetPath>app/ui</targetPath> </resource> </webResources> </configuration> </plugin>
改完之后执行mvn clean package重新构建即可解决问题。
内容的提问来源于stack exchange,提问作者hell_storm2004
相关产品推荐
相关产品推荐

