每次我对我的 POM 进行最微小的更改时,Intellij 都会在项目结构输出目录设置中删除我的爆炸工件的 .war 扩展名。这会导致 Intellij 的运行/调试配置出错:
工件“XXXX:战争爆炸”的扩展名无效。
为了解决这个问题,我必须手动覆盖项目结构输出目录设置。每次我对 POM 进行最细微的更改时,我都必须返回输出目录设置并手动将“.war”附加到输出目录设置的末尾。这变得非常古老和令人沮丧。
例如我必须改变这个:
E:\workarea\enterp\application\target\application
对此:
E:\workarea\enterp\application\target\application.war
如果我手动设置 Maven WAR 插件 outputDirectory 配置如下,这根本没有帮助:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<!-- Output directory of artifact:war exploded keeps losing the .war extension -->
<outputDirectory>${project.build.directory}.war</outputDirectory>
</configuration>
</plugin>
我该如何解决这个问题?
编辑:
这是完整的构建配置:
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation
processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<!-- Output directory of artifact:war exploded keeps losing the .war extension -->
<outputDirectory>${project.build.directory}/${project.artifactId}.war</outputDirectory>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The WildFly plugin deploys your war to a local WildFly container -->
<!-- To use, run: mvn package wildfly:deploy -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</build>
第二次编辑:
我发现一种解决方案是在构建配置中将“.war”附加到 ${project.artifactId} 中,例如:
<finalName>${project.artifactId}.war</finalName>
并从插件配置中删除 outputDirectory。所以构建配置应该是这样的:
<build>
<!--
Maven will make finalName the name of the generated war.
NOTE: Output directory of artifact:war exploded keeps losing the .war extension
http://youtrack.jetbrains.com/issue/IDEA-86484
http://youtrack.jetbrains.com/issue/IDEA-95162
The solution is to append ".war" to ${project.artifactId}, below:
-->
<finalName>${project.artifactId}.war</finalName>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation
processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The WildFly plugin deploys your war to a local WildFly container -->
<!-- To use, run: mvn package wildfly:deploy -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</build>
免责声明:如果您使用此解决方法,请注意,当您部署未爆炸的 WAR 工件时,文件名将命名为 XXXX.war.war。它可以工作——我在 Intellij 中将工件部署为 WAR 文件——但它很难看。
INFO [org.jboss.as.server.deployment](MSC 服务线程 1-7)JBAS015876:开始部署“XXXX.war.war”(运行时名称:“XXXX.war.war)”
如果有人可以告诉我如何配置 Intellij 项目以使用 Maven 来选择一个或另一个 finalName 值,具体取决于我是部署 WAR 文件还是展开的工件,那么这个问题将得到充分回答。
<!-- Exploded artifact -->
<finalName>${project.artifactId}.war</finalName>
<!-- WAR file (unexploded) artifact -->
<finalName>${project.artifactId}</finalName>