Alex’s Weblog

My personal blog

WEB-INF Directory

Today I would like to explore more how the WEB-Content directory is structured, and mainly how the Web.xml file. I will do this using mainly [1], that is the official information from SUN.

The structure of the WEB-INF is not too complicated.

/WEB-INF/

/WEB-INF/web.xml

/WEB-INF/lib/

/WEB-INF/classes/

The /classes directory for servlet and utility classes. The classes in this directory must be available to the application class loader.

The /lib area for Java ARchive files. These files contain servlets, beans, and other utility classes useful to the Web application.

The web.xml file is an xml file ( ahhhh!!) that contains the configuration of the servlet.

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app id=”WebApp_ID” version=”2.4″ xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>
<display-name>ZSVNXmlRpcServer
</display-name> <servlet>
<description/>
<display-name>rpc</display-name>
<servlet-name>rpc</servlet-name>
<servlet-class>
com.zagile.scm.servlet.ZSCMXmlRpcServlet
</servlet-class>
<init-param>
<param-name>enabledForExtensions</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>rpc</servlet-name>
<url-pattern>/rpc</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>view.jsp</welcome-file>
</welcome-file-list>
</web-app>

Above there is an example of an web.xml file:

There is an good site with references to each TAG used on this file [2]. I will put the one that I find more important here, but go to that page if you need more information.

servlet-class –     The fully-qualified class name of the servlet. Use only one of either the <servlet-class> tags or <jsp-file> tags in your servlet body.

init-param –    Contains a name/value pair as an initialization parameter of the servlet. Use a separate set of <init-param> tags for each parameter.

welcome-file –    File name to use as a default welcome file, such as index.html

servlet-mapping –    The servlet-mapping element defines a mapping between a servlet and a URL pattern.

I wrote this post because I was facing problems due to some problems in my web.xml. This was the error that that were happening when I tried to rise the server:

org.apache.catalina.loader.StandardClassLoader@119cca4
com.sun.ws.rest.impl.container.servlet.ServletAdaptor
java.lang.ClassNotFoundException: com.sun.ws.rest.impl.container.servlet.ServletAdaptor
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)

My web.xml it was like the old one but with this lines more

</servlet>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.ws.rest.impl.container.servlet.ServletAdaptor</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>

The program was complaining about that the class was not found, what was correct, I didn’t use this classes so I removed it from my web.xml file and voilà it worked. It seems that these lines were added for the Netbeans that my friend used to open the project I am working( I use eclipse). Well probably I am not an expert in web.xml file, but I am able to understand how it works.

If someone could explain why the netbeans added those lines I would appreciate.

[1] – http://cds-esd.sun.com/ESD6/JSCDL/servlet/2.4-fr/servlet-2_4-fr-spec.pdf

[2] – http://edocs.bea.com/wls/docs61/webapp/web_xml.html

Novembro 27, 2008 Publicado por alexpinheiro | Programming | | Sem comentários ainda

Calling an external executable program in a JAVA program

Today I was struggling to call an executable program inside a Java Program. I was used to do it using the C/C++. Searching on the internet I found two classes

Runtime and Process Class

A basic example

Process processo = Runtime.getRuntime().exec("java");
InputStream ips = processo.getInputStream();

Accordingly to Java documentation:

“Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.”

This class provides some information about the environment that the class is running over and also some features. The one that I was looking for is provide by the method exec that return to us a object from class Process citing the same source:

“…can be used to control the process and obtain information about it.”

It’s possible also to send arguments to the program called calling the method with the signature

exec(String[] cmdarray).

I hope this can be useful for someone. See ya!

Novembro 11, 2008 Publicado por alexpinheiro | Programming | | Sem comentários ainda