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

Pat*_*ner 21 intellij-idea maven java-ee-7 intellij-13

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

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

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

我必须改变这个:

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>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

编辑:

这是完整的构建配置:

    <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>
Run Code Online (Sandbox Code Playgroud)

第二次编辑:

我发现一个解决方案是在构建配置中将".war"附加到$ {project.artifactId},例如:

<finalName>${project.artifactId}.war</finalName>
Run Code Online (Sandbox Code Playgroud)

并从插件配置中删除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>
Run Code Online (Sandbox Code Playgroud)

免责声明:如果您使用此解决方法,请注意,在部署未爆炸的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>
Run Code Online (Sandbox Code Playgroud)

Ale*_*uda 33

有一种方法可以在IntelliJ中修复它,而无需更改你的pom.xml文件,添加一个引用爆炸战争(或者在我的情况下,爆炸的耳朵)的工件,并且它不会每次都被踩踏IntelliJ重新导入maven pom(s).这是如何做:

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

  2. 编辑运行配置,在"部署"选项卡中,删除当前爆炸的war/ear工件

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

  4. 使用加号按钮添加新的战争或(在我的情况下)耳朵爆炸的神器 添加新的战争或耳朵爆炸神器

  5. 给它命名,然后编辑Output目录以添加适当的扩展名(.war或.ear) 重命名输出目录以添加扩展名

  6. 在您看到的"输出布局"部分中<output root>,使用加号按钮添加工件 在输出布局中添加新工件

  7. 选择所需的爆炸工件 选择所需的爆炸工件

  8. 再次编辑运行配置,在"部署"选项卡中,添加新的变通方法爆炸工件 在运行配置中部署新工件

感谢Nikolay Chashnikov在他对bug报告的评论中对此进行了描述


Eng*_*ery 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>
Run Code Online (Sandbox Code Playgroud)