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

Memetic Algorithms

Memetic Algorithms for those, Who don’t know these kind of algorithms they are genetic or evolutionary algorithms more local search. First of all I think I need to explain the genetic algorithms.

The genetic algorithms are a heuristic, “a method to help solve a problem, commonly an informal method” [1]. The genetic algorithms were developed by John Holland on the sixties. He was studying how the evolution theory works and trying to apply this to computers. He’s technique is fairly simple, let’s say that a solution is an individual, it could be bad or a good solution. So if we have more than one possible solution we have a population. So we need that our individuals evolutes and become better individuals.

Each individual is compound of genes, for example in a clustering problem each point would be a gene and its group would be the gene value. The mechanisms used to evolution are mutation and crossover. The first one mutate a specific gene of an individual, in the other side the crossover uses other components of the population to create a new individual.

Figura 1 – Clustering Problem

For example if we want to look for the better way to separate the points above the representation would be:

1 2 3 3 4 1 2 3

So we could mutate the value of a gene to any other group, what would be equal to change randomly the group of a point, and the other thing that we could do would be to try to recombinate two individuals from the population for instance:

Crossing the two individuals:

1 2 3 3 4 1 2 3
3 2 1 2 3 4 4 2

We would have:

3 2 1 3 4 1 4 3

There is needed also a way to compare the solutions, in the clustering problem we could compare the total SSE of the individual, SSE is the Euclidian distance from the point to the centroid of the group its belongs.

Maybe you doubt that this kind of way of resolve a problem can works, but believes me it really works, this kind of algorithms aren’t trying to find the perfect solution they are trying to find one good solution in a reasonable time. There are a lot of serious research already done in this kind of algorithms and a lot of real projects already using it.

The algorithm above is a memetic algorithm because as you can see it works localSearch to improve the solution. In the clustering problem the localSearch chose to a point the group that has his centroid more near of the point.

1 – http://en.wikipedia.org/wiki/Heuristic

2 – Matteucci, M. (17 de setembro de 2003). A Tutorial on Clustering Algorithms. Acesso em 20 de novembro de 2008, disponível em Matteo Matteucci: http://home.dei.polimi.it/matteucc/Clustering/tutorial_html/

3 – Mendes, A. d. (1999). ALGORITMOS MEMÉTICOS APLICADOS AOS PROBLEMAS DE SEQUENCIAMENTO EM MÁQUINAS. Campinas.

4 – Mez., P. (2000). Memetic Algorithm for Combinatorial Optimization Problems: Fitness Landscapes and Effective Search Strategies.

5 – Mitchell, M. (1998). An Introduction to Genetic Algorithms. MIT Press.

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

Difference Between Frames and Description Logic

This post has the goal to discuss in few lines the differences between Frames Technology and Description Logic Based Languages. For the ones that don’t know these terms, OO languanges are Frame based, and OWL is a Description Logic Language. The differences between this two worlds are important because when we are working with ontologies it is a common practice model in a O.O. modeling language (UML) and later translate it to a Description Logic Language (OWL-lite or OWL-DL). If we aren’t aware of the differences between the two worlds we can have some problems when doing the mapping between the model and its implementation.

A DL terminology includes a set of primitive concepts and roles(properties) as well as definitions of complex concepts and roles. The definitions of complex concepts and roles are given via descriptions that are built using a set of constructors, which vary from one DL to another. The strength of DLs is that they are associated with algorithms for subsumption checking, automatic classification and instance recognition.[1]

Frame logic (FL) accounts in a clean, declarative fashion for most of the structural aspects of object-oriented and frame based languages[3]. F-logic stands in the same relationship to the object oriented paradigm as classical predicate calculus stands to relational programming. Although the Frames Technology most well known example is the OO programming languages, there are some ontology languages based on Frames, one example is F-Logic, and the Protégé itself one of the most known ontology editors is based on frames. There is also a reasoner to F-Logic called Florida[2].

  • DLs rely on the ontological distinction between concepts and elements. FL blows away this distinction.
  • FL: closed-world and domain-closure assumptions. DL: open-world and open-domain assumptions.
  • FL: class definition necessary and sufficient.
  • DL don’t uses the unique name assumptions[4] whereas FL includes term equality.
  • DL don’t provides control knowledge. The user it is only able to provide declarative knowledge.

I need to do some research yet to understand how protégé works since it is a frame based editor, but OWL more used is the OWL-DL.

[1] D. Fensel, M.-C. Rousset and S. Decker – Workshop on Comparing Description and Frame Logics

[2] http://en.wikipedia.org/wiki/F-logic

[3] Logical Foundations of Object Oriented and Frame Based Languages – Michael Kifer, Georg Lausen and James Wu

[4] http://en.wikipedia.org/wiki/Description_logic

Novembro 18, 2008 Publicado por alexpinheiro | Modelling, Uncategorized | , , | Sem comentários ainda

Constructor Class

Today I was trying to create na standard Factory design pattern to a bunch of classes that I created. Using JAVA reflection classes I have designed some cool stuff:

 

    protected IGenClass createObject (Class objClass) throws NoSuchMethodException, Exception{

        Constructor constructors = null;

        try {

            constructors = objClass.getConstructor();

        }catch (NoSuchMethodException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        return constructors.newInstance(sIndividual);

    }

 

In this simple case would be the same that wrote the code

IGenClass obj = new ImplGenClass();

 

I know this is not a great thing, but use some imagination, this can be a great thing to make easy to create a bunch of factories.

I hope this can be useful.

Novembro 13, 2008 Publicado por alexpinheiro | Uncategorized | | 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