39

Could someone explain the main differences (or provide a link to) between glassfish-web.xml, sun-web.xml and web.xml?

Can I use just glassfish-web.xml in my webapp and skip the others?

Neuron
  • 5,141
  • 5
  • 38
  • 59
sasha_trn
  • 1,935
  • 2
  • 23
  • 30
  • See also: http://stackoverflow.com/questions/20539842/the-difference-between-web-xml-beans-xml-applicationcontext-xml-etc – Tim B Sep 15 '14 at 14:38

2 Answers2

62
  • web.xml: Standard deployment descriptor defined by Java EE (Servlet JSR in particular, but used by many JSRs). It is used to specify the metadata used by the web container to deploy the application in a portable manner across application servers (such as the URL endpoint of a servlet). In Java EE 6 and beyond, it is optional (depending on technologies that you use) when metadata is provided by annotations in your Java code, like @WebServlet.
  • glassfish-web.xml: Each application server offers implementation-specific features. To configure these features for GlassFish, use glassfish-web.xml. This is documented in the GlassFish Documentation.
  • sun-web.xml: Legacy application-server specific deployment descriptor, and has been replaced by glassfish-web.xml. It no longer made sense to have this name after Sun was acquired by Oracle. This file name is still supported for backwards compatibility, but you should migrate to glassfish-web.xml.

You may or may not need a web.xml file. It depends on the Java EE features you use. By default, don't use any of these files and simply use Java EE annotations like @WebServlet. As you build out your app and perhaps begin using some features that require the web.xml file (like to define the JavaServer Faces FacesServlet), then use a web.xml file. As for the glassfish-web.xml, you only use one if you have GlassFish-specific features to configure for your application.

The Java EE tutorial is also a good way to learn Java EE, and is bundled with the Java EE 7 SDK along with GlassFish 4.

John Clingan
  • 3,324
  • 21
  • 13
  • hi, could you explain to me where does web logic .xml in all of this thanks – shareef Feb 22 '14 at 19:37
  • weblogic.xml is similar to glassfish-web.xml, but contains configuration options specific to WebLogic. See http://docs.oracle.com/middleware/1212/wls/WLPRG/overview.htm#WLPRG111 – John Clingan Feb 25 '14 at 00:10
-5
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>BusProject</display-name>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
   <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring-servlet.xml</param-value>
  </context-param>  
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
 </web-app>
  • 2
    Some narrative would be nice here, especially since that is what OP is asking for. The heart of the question is "explain main differences", which this monolith of an answer clearly does not do. – Mad Physicist Mar 27 '17 at 19:31