Friday, August 21, 2009

Spring ContextLoaderListener ClassNotFoundException

I ran a Java web application with Maven, Tomcat in Eclipse. When the application started, Eclipse console has the exception:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Of course, I did not forget to define Spring dependency in Maven pom.xml. But when I checked the deployment at
ECLIPSE_WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\APPLICATION\WEB-INF\lib
, there was no Jar indeed. So it looked like something went wrong with Eclipse/Tomcat/Maven deployment.

I did a couple of things to make it work.
1. Get rid of duplicated classes. For example, the dependency on spring-aspects also brings in spring-beans and spring-core, which are already part of spring dependency. Tip: use "mvn dependency:tree" to the dependency tree. So I need to exclcude it by
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>2.5.6</version>
<!-- exclude spring-beans which is part of spring-2.5.6.jar -->
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
2. Right click project > Maven > Update Project Configuration. Disable and re-enable Maven dependency management if necessary.

Now I found all the required jars in the right place. I started the application and no error!

This seems to be a glitch with Eclipse Maven plugin. I need to keep an eye on it.

Thursday, July 30, 2009

Search Documentum including old version

A document in documentum is versioned. By default, documentum only searches the current version of documents. To include old version, add (all) in the query like this example.

select * from opp_assessment(all)
where ref_doc_num = '0919999980028b06'

Wednesday, July 22, 2009

Escape in JSTL XML tag

In JSTL XML tag, if the data has characters like "<", it will be escaped by default. To turn it off, set escapeXml to false.

<x:out select="$n/STATUS" escapeXml="false" />

Friday, June 26, 2009

Remove from Hibernate Set

Suppose you have one-to-many bi-directional mapping between Category and Item.

public class Category {
Set items;
}

public class Item {
Category category;
}

To remove an item from Category, you need to do this

category.getItems.remove(item1);
delete(item1); // delete() is from Hibernate API

The first line takes out the relationship while the second one deletes it.

Wednesday, June 24, 2009

Use log4j in JSP

http://www.mobilefish.com/developer/log4j/log4j_quickguide_jsp.html

Use the following section in pom.xml to declare the dependency in maven
<dependency>
<groupId>taglibs</groupId>
<artifactId>log</artifactId>
<version>1.0</version>
</dependency>

Monday, June 22, 2009

Format date in Hibernate Mapping

<property name="birthday" type="date" formula="trunc(BIRTHDAY)">
<column length="20" name="BIRTHDAY"/>
</property>

Tuesday, June 9, 2009

Update jquery tablesorter cache

jquery table sorter caches the data. You need to update the cache after removing table rows. Otherwise, the removed rows will show up again. Here is how to update the cache.

$('#myTable').trigger("update");