Setting Context-Root with Glassfish Application Server

血红的双手。 提交于 2019-12-24 06:13:14

问题


I have a EJB WEB Application with an Glassfish Application-Server. Now i want the Context-Root like this "/". My current URL is "http://localhost:8080/Make" but i want this one :"http://localhost:8080" without the "Make" as my Application Name currently is. But hen i deploy it and tip "http://localhost:8080" i got the "Server is running" page from glassfish So i trie to figure out what i can do. I have create a glassfish-web.xml in my WEB-INF folder

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

Nothing happens. Than i have create a sun-web.xml in the same folder:

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

Also i hvae trie with a glassfish-application.xml and application.xml. So what must i do to take this effect?

PS: this is my web.xml and i deploy as EAR file

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

EDIT: The application.xml in the WEB-INF Folder

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

回答1:


Setting the context root to / is not enough to be able to access your web app only by typing http://yourdomain.org because Glassfish will display the "Your server is running" message found in index.html`.

To get your app launch. set the Default Web Module drop down found in Configuration | server-config | Virtual Servers | server (in the Web console) to the name of your web app.




回答2:


The glassfish-web.xml you posted seems to be ok.

If you deploy you application as EAR, you may need and application.xml like this:

<?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>something</application-name>
  <display-name>something</display-name>
  <module>
    <web>
      <web-uri>your_webapplication.war</web-uri>
      <context-root>/</context-root>
    </web>
  </module>
  <module>
    <ejb>your_ejb_services.jar</ejb>
  </module>
  <library-directory>lib</library-directory>
</application>

This is just a template example. You can also have multiple web-modules and ejb-modules.

If you deploy via the Glassfish Admin UI you can set the context root when deploying:

If you use asadmin for deploying you can set the context root like this:

asadmin deploy --name something --contextroot / /path/of/your/war.war


来源:https://stackoverflow.com/questions/41585188/setting-context-root-with-glassfish-application-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!