首页 > 解决方案 > WildFly Maven 插件 - 设置空白上下文根

问题描述

我正在使用 Maven WildFly 插件,并且在我的pom.xml(版本是2.0.1.Final并且路径指向本地 WildFly8.2.1.Final服务器)中有以下内容。

<build>
    <plugins>
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>${wildfly.version}</version>
            <configuration>
                <jboss-home>${wildfly.path}</jboss-home>
            </configuration>
        </plugin>
    </plugins>
</build>

应用程序正在按预期进行部署,localhost:8080/myArtifactId-myVersion因为默认行为是使用 WAR 名称。但是,我想更改上下文根以便可以通过localhost:8080/(即我想要一个空白的上下文根)访问应用程序。

方法一:更改 Pom 配置

我可以如下更改我的finalName构建设置pom.xml

<build>
    <finalName>newContextRoot</finalName>
</build>

这会正确地将 url 更新为localhost:8080/newContextRoot. 然后我尝试将其更改为空白值。

<build>
    <finalName></finalName>
</build>

但是,这会导致Value must not be empty我的 IDE 出现错误,当我尝试构建它时会失败,说Error assembling WAR: A zip file cannot include itself.

方法 2:更改插件配置

可能更好的解决方案是更改 Maven WildFly 插件本身的配置。在该<configuration>部分下,我可以添加以下内容。

<name>anotherContextRoot.war</name>

这正确地将 url 更改为localhost:8080/anotherContextRoot. 因此,我再次尝试创建一个空白名称,如下所示。

<name>.war</name>

但是,这会导致IllegalArgumentException: Empty name segment is not allowed for module.

问题

有谁知道使上下文根为空白的适当方法?提前致谢。

标签: mavenwildfly

解决方案


我设法弄清楚了这一点。jboss-web.xml除了将文件添加到目录中之外,您无需执行任何操作WEB-INF,如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/</context-root>
    <default-encoding>UTF-8</default-encoding>
</jboss-web>

这将设置上下文根并覆盖插件正在执行的操作。

希望这对其他人有帮助。


推荐阅读