Wednesday, November 20, 2013

Conflicting classes in multiple dependent jars

Working in Teradata, I discovered an issue related to multiple versions of Spring dependent jars. The problem is that we use Ivy to add project jar dependence. Each jar/project can have different versions of Spring jars in its library. For a master project which depends on several other base projects and having its own Ivy library, as a whole, its library will have different version of Spring jar files. These jars can contain same class with different contents. Some earlier versions might not have the implementation for certain methods added later. This problem is mostly applicable in Eclipse when all the library files are loaded in CLASSPATH, including the library files for dependent projects. A standalone jar invocation can avoid this issue by providing a precise Manifest file containing only needed jars!

One error I got when running the project in Eclipse is as below:

Invalid property 'maxConcurrentConsumers' of bean class [org.springframework.jms.listener.DefaultMessageListenerContainer]

Notice due to the usage of Spring injection, the above error is not discovered at compilation time. In the example DefaultMessageListenerContainer.setMaxConcurrentConsumers is provided in Spring 2.0.6 but not in Spring 2.0. Other issues are also found including Spring's support for Circular references.

I found it is hard to remove the dependence of the old versions of Spring jars from dependent projects. Even using "transitive = 'false'" tag on the Ivy configuration does not work. I have to live with multiple versions of jars containing the same class. To make sure using the latest version of the jar, I have to depend on the JVM class loader order. Fortunately I found this is doable within eclipse. Eclipse's JVM will load the jars in the order of your specification in the "Java Build Path" --> "Order and Export". As long as the correct version of the jar (or ivy.xml) is before the obsolete jar (or dependent project), the issue can be avoided.

Wednesday, March 12, 2008

Configure MQ on iSeries

To run MQ on iSeries, one must start the MQ subsystem with command:

strsbs sbsd(qmqm/qmqm)

Then we can access the queue manager with "wrkmqm" command.

Europa catch

Europa is the name for Eclipse 3.3 EE version. I recently began to Europa for JEE5 development. Found a big catch. I used Europa with JBoss4.2.2. For some reason I found I can not deploy a class named "TestServlet" as a web service class. No matter what the package name I gave. It always result in error "Allocate exception for servlet TestServlet". Very strange.

Wednesday, February 20, 2008

import signature files from iSeries

Here is how I imported the company's digital certificate (key pair) from iSeries machine:

1. get the KDB file from the iSeries file structure and move it to a windows box
2. Use a java-based tool named iKeyMan.bat to open the key db file. The tool is shipped with Websphere product.
3. export the key pair to an existing "jks" format file which is java keystore. The file will server as the keystore, and can be used to sign jar files.

Thursday, February 07, 2008

DB connection error in websphere + iSeries

Recently we have a stale connections problems in a WebSphere App server running on iSeries database. I realized the problem might be the getConnection() method is not synchronized(serialized) at the JDBC driver implementation. So two threads can potentially get the same connection and step on each other. It sounds like a bug to me. The solution is easy, just synchronize the code that call getConnection() method, of course, I am assuming the calling class is already in a Singleton mode.

Friday, January 18, 2008

Some more tips

1. I found a cookie problem recently, basically the cookie can not be set from a web app on a linux server. It turned out the server had a very off time. And the cookie expiration time is calculated by current server time + cookie life time. If the server is behind the time too much, it will no set the cookie to the browser any more.

2. Always use varchar instead of char in DB column design to save space if the column's String length is unknown. In DB2 use varchar type directly, in Oracle we should use varchar2 type since varchar is reserved for other purpose according to one article.

Thursday, March 08, 2007

Load a resource file in ear environment

Three issues
1. the properties files must be in the class path of the application module trying to read it
2. you have to use the correct class loader (Thread.currentThread().getContextClassLoader()).
3. call classloader's getResource(String propResource) method.

It will not work by simply using ClassLoader.getSystemResource() method.

Thursday, March 01, 2007

two tips

Regular Expressions:
using $1, $2.. to match find result. use () to group characters. * + are applied after the searching characters. using \w for all alphanumeric char.

How to throw business exception in web service calls.
The best way is to define some serializable fields when creating the exception class which will be returned by a web service method call. Otherwise when calling wsdl2java, it will automatically create a message field and getMessage() for you, which will cause problem in RAD tool. The reason for all this I guess is because the Exception class itself is not Serializable, and its fields can not be transfered. So it requires developer to create a subclass of Exception with its own fields to hold the exception code and message. Which can be shown within the fault segment.