Maven Intellij创意作品';XXXX:战争爆发了';具有无效的扩展名

Maven Intellij创意作品';XXXX:战争爆发了';具有无效的扩展名,maven,intellij-idea,java-ee-7,intellij-13,Maven,Intellij Idea,Java Ee 7,Intellij 13,每次我对POM进行哪怕是最微小的更改,Intellij都会在项目结构输出目录设置中删除分解工件的.war扩展名。这会导致Intellij的运行/调试配置出错: 工件“XXXX:战争爆发”的扩展名无效。 为了解决这个问题,我必须手动覆盖项目结构输出目录设置。每次我对POM进行哪怕是最微小的更改,我都必须返回到输出目录设置,并手动将“.war”附加到输出目录设置的末尾。这是非常古老和令人沮丧的 e、 g.我必须改变这一点: E:\workarea\entrep\application\target\

每次我对POM进行哪怕是最微小的更改,Intellij都会在项目结构输出目录设置中删除分解工件的.war扩展名。这会导致Intellij的运行/调试配置出错:

工件“XXXX:战争爆发”的扩展名无效。

为了解决这个问题,我必须手动覆盖项目结构输出目录设置。每次我对POM进行哪怕是最微小的更改,我都必须返回到输出目录设置,并手动将“.war”附加到输出目录设置的末尾。这是非常古老和令人沮丧的

e、 g.我必须改变这一点:

E:\workarea\entrep\application\target\application

为此:

E:\workarea\entrep\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>

maven战争插件
${maven.war.plugin.version}
${project.build.directory}.war
我如何解决这个问题

编辑:

以下是完整的构建配置:

    <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>

${project.artifactId}
maven编译器插件
${maven.compiler.plugin.version}
${maven.compiler.source}
${maven.compiler.target}
maven战争插件
${maven.war.plugin.version}
${project.build.directory}/${project.artifactId}.war
假的
org.wildfly.plugins
wildfly maven插件
${version.wildfly.maven.plugin}
第二次编辑:

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

<finalName>${project.artifactId}.war</finalName>
${project.artifactId}.war
并从插件配置中删除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>

${project.artifactId}.war
maven编译器插件
${maven.compiler.plugin.version}
${maven.compiler.source}
${maven.compiler.target}
maven战争插件
${maven.war.plugin.version}
假的
org.wildfly.plugins
wildfly maven插件
${version.wildfly.maven.plugin}
免责声明:如果使用此解决方案,请注意,当部署未爆炸的WAR工件时,文件名将命名为XXXX.WAR.WAR。它可以工作——我在Intellij中将该工件部署为WAR文件——但它很难看

INFO[org.jboss.as.server.deployment](MSC服务线程1-7)JBAS015876:开始部署“XXXX.war.war”(运行时名称:“XXXX.war.war)”

如果有人能告诉我如何配置Intellij项目以与Maven合作,根据我是部署WAR文件还是分解工件来选择一个或另一个finalName值,那么这个问题将得到充分的回答

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

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

${project.artifactId}.war
${project.artifactId}

实际上,您应该将
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>

maven战争插件
${project.build.directory}/${project.artifactId}.${project.packaging}
假的

我想这和这个问题是一样的:


将.war扩展名添加到输出目录,如我的回答所示:

在IntelliJ中有一种方法可以解决这个问题,无需更改pom.xml文件,方法是添加一个引用分解的war(或者在我的例子中,分解的ear)的工件,并且不会在IntelliJ每次重新导入maven pom时都被踩死。以下是方法:

  • 停止/取消部署当前工件部署

  • 编辑您的运行配置,并在部署选项卡中删除当前分解的war/ear工件

  • 打开项目的工件设置并添加新工件

  • 使用加号按钮添加一个新的战争或(在我的例子中)耳朵爆炸工件

  • 给它一个名称,然后编辑输出目录以添加适当的扩展名(.war或.ear)

  • 在您看到的“输出布局”部分中,使用加号按钮添加工件

  • 选择所需的分解工件

  • 再次编辑您的运行配置,并在部署选项卡中添加新的解决方案分解工件


  • 感谢尼古拉·查什尼科夫(Nikolay Chashnikov)在他对

    的评论中描述了这一点,如果我们谈论的是EAR内部的战争,那么通过使用maven EAR插件内部的正确配置,还有另一种解决问题的方法。WAR pom.xml应该保持原样,不做任何更改,但是EAR pom.xml应该包含这样的内容。(请注意${unpack.wars}

    
    org.apache.maven.plugins
    

    使用此解决方案,热交换和资源更新工作正常


    希望这能有所帮助。

    问题在于,每次编辑POM时,项目结构都会丢失添加到输出目录名中的.war扩展名。这是一只虫子。检查我的。如果这是解决方案,那将是一个非常糟糕的解决方案,因为如果我选择使用未分解的WAR工件进行部署,那么我不想部署到${project.build.directory}.WAR。但是,我尝试使用此配置设置来查看它是否会有所不同。事实并非如此。战争中爆炸的神器问题并没有消失。
    <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>