Intellij IDEA工件'XXXX:war explosion'具有无效扩展名

时间:2014-07-13 18:01:16

标签: maven intellij-idea java-ee-7 intellij-13

每次我对POM进行最微小的更改时,Intellij会在Project Structure输出目录设置中删除爆炸工件的.war扩展名。这会导致Intellij的运行/调试配置出错:

神器' XXXX:战争爆炸'扩展名无效。

为了解决问题,我必须手动覆盖Project Structure输出目录设置。每当我对POM进行最小的更改时,我必须返回到Output目录设置并手动追加" .war"到输出目录设置的末尾。这变得非常古老和令人沮丧。

e.g。我必须改变这个:

E:\工作区\ enterp \应用\目标\应用

到此:

E:\工作区\ enterp \应用\目标\ 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>

第二次编辑:

我发现一个解决方案是附加&#34; .war&#34;在构建配置中为$ {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:开始部署&#34; XXXX.war.war&#34; (runtime-name:&#34; XXXX.war.war)&#34;

如果有人可以告诉我如何配置Intellij项目以使用Maven来选择一个或另一个finalName值,这取决于我是否部署WAR文件与爆炸工件,那么这个问题将得到充分的回答。

<!-- Exploded artifact --> 
<finalName>${project.artifactId}.war</finalName>

<!-- WAR file (unexploded) artifact --> 
<finalName>${project.artifactId}</finalName>

4 个答案:

答案 0 :(得分:32)

有一种方法可以在IntelliJ中修复此问题,而无需更改pom.xml文件,方法是添加一个引用爆炸战争(或者在我的情况下,爆炸的耳朵)的工件,它将无法获得每次IntelliJ重新导入maven pom时都会踩踏。方法如下:

  1. 停止/取消部署当前的工件部署

  2. 编辑您的运行配置,并在“部署”标签中删除当前爆炸的战争/耳部工件

  3. 打开项目的Artifacts设置并添加新工件 Add new artifact

  4. 使用加号按钮添加新的战争或(在我的情况下)耳朵爆炸的神器 Add new war or ear exploded artifact

  5. 为其命名,然后编辑Output目录以添加相应的扩展名(.war或.ear) Rename output directory to add extension

  6. 在您看到<output root>的“输出布局”部分中,使用加号按钮添加工件 Add new artifact in output layout

  7. 选择所需的爆炸工件 Select the desired exploded artifact

  8. 再次编辑运行配置,并在“部署”选项卡中添加新的变通方法爆炸工件 Deploy new artifact in run configuration

  9. 感谢Nikolay Chashnikov在他对bug report

    的评论中对此进行了描述

答案 1 :(得分:4)

实际上,您应该单独保留finalName属性,否则您将遇到您描述的问题。相反,您应该更改maven war插件的配置以使用webappDirectory,如下所示:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webappDirectory>${project.build.directory}/${project.artifactId}.${project.packaging}</webappDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

答案 2 :(得分:2)

如果我们在EAR中讨论WAR,还有另一种方法可以通过在maven-ear-plugin中使用正确的配置来解决您的问题。 WAR pom.xml应保留原样,不做任何更改,但EAR pom.xml应该包含这样的内容。 (请注意&lt; unpack&gt; $ {unpack.wars}&lt; / unpack&gt;

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <version>6</version>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
        <generateApplicationXml>false</generateApplicationXml>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            </manifest>
        </archive>
        <modules>
            <webModule>
                <groupId>com.test.app</groupId>
                <artifactId>test-app-war</artifactId>
                <unpack>${unpack.wars}</unpack>
            </webModule>
        </modules>
    </configuration>
</plugin>

然后您可以添加配置文件默认调试以进行正确的工件组装。

<profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <unpack.wars>false</unpack.wars>
            </properties>
        </profile>
        <profile>
            <id>debug</id>
            <activation>
                <property>
                    <name>debug</name>
                </property>
            </activation>
            <properties>
                <unpack.wars>true</unpack.wars>
            </properties>
        </profile>
</profiles> 

在IntelliJ IDEA中使用调试配置文件来扩展战争和默认配置文件,以便在命令行或CI中构建工件(如果未提供配置文件,默认配置文件将处于活动状态,因此你的构建将像以前一样工作。)

Maven Projects view

使用此解决方案,HotSwap和资源更新按预期工作。

希望这有帮助。

答案 3 :(得分:-1)

我认为这与此问题相同:IntelliJ Artifact has invalid extension

在输出目录中添加.war扩展名,如我的回答所示:https://stackoverflow.com/a/25569266/968988

相关问题