Archive for the ‘Uncategorized’ Category

Maven Junit Report

Wednesday, April 13th, 2005

I wanted to generate a nicely HTML formatted JUnit report for all subprojects in a maven project. This is my solution:

In maven.xml:

<goal name=”junit-report-all”>
<maven:reactor basedir=”${basedir}”
includes=”*/project.xml”
goals=”junit-report:report,xdoc”
banner=”Generating JUnit report”
ignoreFailures=”false”/>
</goal>

In project.xml (at the bottom, under <builds>):

<reports>
<report>maven-junit-report-plugin</report>
</reports>

In project.properties:

maven.test.skip=false
maven.junit.fork=true
maven.test.failure.ignore=true

Now execute “maven junit-report-all”. For every subproject, a JUnit report will be produced!

Hibernate Moving Day

Wednesday, April 13th, 2005

Moving day!

I decided to upgrade from Hibernate 2.1.8 to Hibernate 3.0rc1. Didn’t seem so difficult, but two problems took a considerable amount of time to figure out: the lazy=”true” by default and the new antlr query parser in weblogic.

What I did:
- Renamed packages from net.sf.hibernate to org.hibernate
- Renamed imports of org.springframework.orm.hibernate.* to org.springframework.orm.hibernate3
- Updated all references to org.springframework.orm.hibernate in the Spring XML and properties files (the database dialect e.g.) to org.springframework.orm.hibernate3

I should mention that we use org.springframework.orm.hibernate3.HibernateInterceptor.

I got this error when I started Tomcat:
“could not initialize proxy – the owning Session was closed”

According to the Spring forum, the solution for this error is to set lazy=”false” in the Hibernate mappings. Instead of doing this, I decided to remove all our calls to Hibernate.initialize() (which was needed because we need some collections in the JSPs that won’t get loaded otherwise). I replaced the AOP HibernateInterceptor with org.springframework.orm.hibernate3.support.OpenSessionInViewFilter which is an implementation of the “Open Session In View” pattern. The idea is that a Hibernate Session is opened before every request, and closed afterwards.

The “problem” with this approach is that an explicit session.flush() is needed every time you perform session.save() or session.update(). See the Javadoc for OpenSessionInViewFilter for the reason for this. It is possible to make a subclass of OpenSessionInViewFilter which flushes automatically, but this is not recommended.

The result of this lazy loading is a noticeable reduction of SQL calls (you can check this by setting the Hibernate “show_sql” property to “true”.

Another problem I encountered and that bothered me for some time, was an issue with the new Query parser in Hibernate 3, which uses antlr. The issue and the solution (hack) is described in this Hibernate forum thread. The problem is that weblogic 8 uses the infamous 33 MB weblogic.jar, which already includes a version of antlr. This causes class loading problems and an error since the antlr classes are loaded by the servers classloader and can not see the classes in hibernate3.jar which is inside an ear or a war. This nice line is given as an indication of what went wrong:

CharScanner; panic: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

After this error, System.exit() is called from antlr, which makes it even harder to find what’s wrong (Weblogic just shuts down). The correct solution is to set the Hibernate property “hibernate.query.factory_class” to “org.hibernate.hql.classic.ClassicQueryTranslatorFactory” (in your Spring configuration or in hibernate.properties).

See also this post about a Hibernate antlr patch.

Class Loading Hell

Wednesday, January 19th, 2005

Man, I feel dizzy. Just spend way too much time trying to find the cause of

a java.lang.NoClassDefFoundError: org.apache.struts.tiles.xmlDefinition.I18nFactorySet on BEA Weblogic 8.1.

Struts.jar was inside WEB-INF/lib, so I thought everything was ok.

Apparently the problem was that commons-digester.jar was also loaded in an ejb.jar, which made it unavailable for the I18nFactorySet tiles class in the war.

The solution was to put struts.jar and commons-digester.jar in my ear file and then reference them from inside ejb.jar/meta-inf/MANIFEST.MF and application.war/meta-inf/MANIFEST.MF with something like

Class-Path: struts-1.2.4.jar struts-el-1.2.4.jar commons-digester-1.6.jar

Thanks to Rod Johnson for his excellent chapter 14 on class-loading issues in Expert One-on-One J2EE Design and Development.

Half-life 2

Tuesday, November 16th, 2004

This hasn’t to do with programming, but is still very exiciting: Half-life 2 is out! After having to wait way to long, the game is finally released! Usually I don’t play computer games, but this one is so good it’s worth mentioning here.

It took a lot of patience to install it since the Steam registration servers were overloaded. But finally, I managed to start the game and it looks/plays/feels amazing.

Somehow, I felt the urgent need to play “Peter Gun Theme” from the Blues Brothers while waiting for my registration to complete…

Maven, JUnit and Log4j

Wednesday, November 10th, 2004

I had a hard time trying to let Maven know where to find log4j.properties when running JUnit. Found nothing in the Maven docs or on Google about this. A friend of mine (yo, Maarten!) helped me to find the solution.

I got every time the message “Please initialize the log4j system properly”. I put log4j.properties in almost every possible directory (src/conf, src/java, …).

Add this to project.properties:

#setup for junit testing

maven.junit.sysproperties=log4j.configuration

log4j.configuration=log4j.properties

And add this to project.xml. The trick is that you need to include the log4j.properties file as a resource here.

<unitTest>

<includes>

<include>**/*Test.java</include>

</includes>

<resources>

<resource>

<directory>${basedir}/src/test</directory>

<includes>

<include>**/*.xml</include>

<include>**/*.properties</include>

</includes>

</resource>

<resource>

<directory>${basedir}/src/conf</directory>

<includes>

<include>log4j.properties</include>

</includes>

</resource>

</resources>

</unitTest>

Java 1.5 released

Monday, November 8th, 2004

Java J2SE 1.5 has been released. Read about the new features or download it.

Messenger Plus Spyware

Wednesday, September 29th, 2004

Just spend three hours trying to remove the spyware that came with Messenger Plus. A popup notified me of an update for Messenger Plus, something I don’t really use, but since I’m working on the pc of someone else (who uses it), I did the update. And then I was punished for my never-ending search for updates. I was busy doing something else (deadline was that evening) and clicked Yes on what seemed to me like a user agreement. Now it seems that I agreed to install “sponsor” software. I tried ad-aware, spybot and cwsshredder, but nothing helped to remove the annoying search bar on top and bottom of Internet Explorer. It had even changed my homepage in Firefox!

Following the instructions from Messenger Plus, like uninstalling, installing with sponsor and then uninstalling (!) didn’t help either, probably because one of the anti-spyware tools had corrupted something.

Finally, by going to lop.com, clicking help and then “how to uninstall”, I ran a small program “new_uninstaller.exe” that finally removed the spyware. The “toolbar_uninstaller.exe” that’s also mentioned on lop.com didn’t work.

Not sure to what extend I can trust this software from lop.com, but it did what it promised to do.

I can not agree with the developers of Messenger Plus who say you have clicked to agree to install the adware. They know as good as I that the layout of the setup program is crafted to fool users to think they accept a standard license (there’s no “don’t agree” option, only “agree and install” and “agree and don’t install sponsor”). And don’t tell me that they read every single license they see.

View Cache versus Controller Cache

Wednesday, September 8th, 2004

I implemented today some caching in my JSPs with OSCache. But since we’re working with Spring and Struts, this doesn’t make much sense. The Spring and Struts frameworks are based on the MVC model, so all business objects are fetched in the controller and then passed on to the model/view. The performance gain of not executing the JSP code is very small, since the database access in the controller is still repeated for every page request – and this is the big performance problem. In Hibernate you can cache the result of queries, but then the JSP code is executed for every page. And using a cache both for Hibernate and the JSPs would be weird, since then Hibernate would return results that are not even used by the JSPs…

For the moment, I solved this by placing Custom tags in my JSPs. These tags get an id for an object, get it from the database and then put that object in the pageContext. Then I surrounded these “database” tags with the oscache tags. Performance is a lot better now, but I’m not very happy with this solution since it puts code in the view.

Friday, August 6th, 2004

Wow, this is a nice on-line shop solution: osCommerce. Now I have installed it, I recognize the layout from other sites. Very easy to install, multi-language, complete admin site.

Why bother with programming this myself? Now learning PHP is something more on my to-do list… Although programming without objects is a bit weird for me (procedural programming is something which was replaced by object-oriented programming in my university in the first year).

Wednesday, August 4th, 2004

Finally, Lomboz for Eclipse 3 has been released! This is a very good plugin if you’re doing JSP development since it precompiles the JSPs in Eclipse and highlights the errors, which saves a great amount of time.

I had problems with the plugin since it didn’t seem to show up in Eclipse. Also, I had a lot of “%someParam” menu items. This post gave me the answer: just start Eclipse with “eclipse -clean” to clean up cached info. Apparently some data from the beta releases was cached.