【问题标题】:Intellij IDEA artifact 'XXXX:war exploded' has invalid extensionIntellij IDEA 工件“XXXX:战争爆炸”具有无效扩展名
【发布时间】:2014-09-03 17:26:32
【问题描述】:

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

工件 'XXXX:war exploded' 的扩展名无效。

为了解决这个问题,我必须手动覆盖项目结构输出目录设置。每次我对 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 一起使用,以根据我是部署 WAR 文件还是展开的工件来选择一个或其他 finalName 值,那么这个问题将得到充分回答。

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

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

【问题讨论】:

  • 为什么要更改 pom.xml 中的 finalName?您这样做是为了解决这个错误,还是出于与您的开发/部署工作流程相关的其他原因?

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


【解决方案1】:

有一种方法可以在 IntelliJ 中解决此问题,无需更改您的 pom.xml 文件,方法是添加一个参考爆炸战争(或者在我的情况下是爆炸耳朵)的工件,但它不会得到每次 IntelliJ 重新导入 maven pom(s) 时都会被踩踏。方法如下:

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

  2. 编辑您的运行配置,然后在“部署”选项卡中,删除当前已爆炸的战争/耳朵工件

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

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

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

  6. 在您看到&lt;output root&gt; 的输出布局部分中,使用加号按钮添加工件

  7. 选择所需的分解工件

  8. 再次编辑您的运行配置,并在“部署”选项卡中,添加新的解决方法爆炸工件

感谢 Nikolay Chashnikov 在他对 bug report 的评论中描述了这一点

【讨论】:

  • 使用 Maven 时(修改上面的第 5 步)将 IDEA -> 项目结构 -> ear:ear exploded -> 输出目录下移一层。这是因为 Maven clean/package 期望 target\groupId.artifactId-version.ear 始终是一个文件。因此,在 IDEA 中设置类似“C:\Project\ear\target\idea\groupId.artifactId-version.ear”的内容,注意在路径中添加“\idea\”以及在目录名称中添加 .ear 后缀,现在与同时的 Maven 清理/打包周期没有冲突。
  • 这是迄今为止最简单、最安全的解决方案。谢谢,亚历克斯!
【解决方案2】:

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

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

【讨论】:

  • 如果这是解决方案,那将是一个非常糟糕的解决方案,因为如果我选择使用未爆炸的 WAR 工件进行部署,那么我不想部署到 ${project.build.directory}。战争。但是,我尝试使用此配置设置来查看它是否会有所作为。它没。 WAR爆炸神器的问题并没有消失。
  • 仅供参考,Intellij 错误报告是 here
  • 这个配置对我有用。我猜配置文件可用于根据需要更改目录以克服@PatrickGarner 的担忧
【解决方案3】:

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

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

然后您可以添加配置文件 defaultdebug 以正确组装工件。

<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 中使用 debug 配置文件来扩展战争,使用 default 配置文件在命令行或 CI 中构建工件(如果没有提供配置文件,默认配置文件将处于活动状态,所以您的构建将像以前一样工作)。

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

希望这会有所帮助。

【讨论】:

    【解决方案4】:

    我觉得和这个问题一样:IntelliJ Artifact has invalid extension

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

    【讨论】:

    • 问题是每次编辑 POM 时,项目结构都会丢失添加到输出目录名称的 .war 扩展名。这是一个错误。检查我的earlier answer to that question
    猜你喜欢
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 2015-05-19
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多