使用 Glassfish 应用服务器设置上下文根

Cap*_*i-N 4 glassfish

我有一个带有 Glassfish 应用程序服务器的 EJB WEB 应用程序。现在我想要像这样的“/”上下文根。我当前的 URL 是“ http://localhost:8080/Make ”,但我想要这个:“ http://localhost:8080 ”,不带“Make”作为我当前的应用程序名称。但是当我部署它并提示“ http://localhost:8080 ”时,我从 glassfish 得到了“服务器正在运行”页面,所以我试图弄清楚我能做什么。我在 WEB-INF 文件夹中创建了 glassfish-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish   Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-  web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>/</context-root>
</glassfish-web-app>
Run Code Online (Sandbox Code Playgroud)

什么都没发生。我在同一文件夹中创建了一个 sun-web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC 
 "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN"   
 "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app error-url="">
<context-root>/path/to/our/App</context-root>
</sun-web-app>
Run Code Online (Sandbox Code Playgroud)

我还尝试使用 glassfish-application.xml 和 application.xml。那么我必须做什么才能达到这个效果呢?

PS:这是我的 web.xml,我部署为 EAR 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Make</display-name>
<mime-mapping>
<extension>xhtml</extension>
<mime-type>application/xml</mime-type>
</mime-mapping>
<welcome-file-list>
 <welcome-file>anmeldung.xhtml</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
 <error-page>
 <exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/anmeldung.xhtml</location>
</error-page>
<context-param>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
 </context-param>
 <context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bootstrap</param-value>
 </context-param>
 <context-param>
<param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
<param-value>/WEB-INF/resources</param-value>
 </context-param>
 <context-param>
 <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
 </web-app>
Run Code Online (Sandbox Code Playgroud)

编辑:WEB-INF 文件夹中的 application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<application-name>Make</application-name>
<display-name>Make</display-name>
<module>
<web>
  <web-uri>Make.war</web-uri>
  <context-root>/</context-root>
</web>
 </module>
<module>
  <ejb>makeITown.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
Run Code Online (Sandbox Code Playgroud)

Pie*_*e C 5

将上下文根设置为/不足以仅通过键入来访问您的 Web 应用程序,http://yourdomain.org因为 Glassfish 将显示在 index.html` 中找到的“您的服务器正在运行”消息。

让您的应用程序启动。Default Web Module将(在 Web 控制台中)找到的下拉列表设置Configuration | server-config | Virtual Servers | server为您的 Web 应用程序的名称。