如何在 java ee 7 应用程序中设置上下文根

How to set the context root in java ee 7 application

我看过 this link and this one but I can't find the sun-web.xml anymore. I am going through the java ee 7 tutorial, specifically the hello1 申请。我不明白应用程序如何知道 /hello1 是上下文根,我的意思是,我没有在 /WEB-INF/web.xml 下的 web.xml 文件中的任何地方看到它。 glassfish 是如何知道的,我们如何将其更改为 /abc 等。

默认情况下,上下文根与包名称相同。

如果你使用wildfly或者jboss,你可以在webapp/WEB-INF/中添加jboss-web.xml来改变上下文根,内容如:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
      http://www.jboss.com/xml/ns/javaee
      http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
    <context-root>yourownroot</context-root>
</jboss-web>