Dependency management problems

May 26, 2009

Dependency management nowdays is used in many projects. It’s nice the idea to have someone taking care about downloading dependencies for you and the fact that you can easily switch dependencies. But in practice this aproach has some problems in contrast to old “commit your jars”.

The first argument people use in favor of dependency managament is that it saves server disk space. I think cheap disk space alone is not a good argument to change development process considering the issues bellow.

The major problem with dependency managament, is that your project dependends on a external repository, that may change over time. If the repository changes, the results of your build may change. This causes serious problems with basics of SCM, reproducible builds and tags for example. The essence of tags is to build a project in the exact state it was in a given time. This benefit is lost if a project depends on a external repository, that cannot be tagged along with it.

Another issue is that your build may not work in other developers machine. This happen, for example, if your have declared a dependency that only exists in your local repository (manually installed or downloaded through a different repository).

Also, there is complexity added by dependency management itself. Dependency descriptors (XMLs), learning curveĀ  of the tool (high if you are using maven), repository configuration, etc.

Talking about maven there has already been many criticism to it, so I will not reiterate here.

A hybrid aproach can be a good choice, but I have no personal experience with it.


How to use logical OR with grep

April 9, 2009
grep -E "search1|search2" file.txt

How to read a properties file on the classpath

March 20, 2009

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import org.apache.log4j.helpers.Loader;
...
String propertiesFile = "myfile.properties";
URL url = Loader.getResource(propertiesFile);
if ( url == null ) {
throw new FileNotFoundException( propertiesFile + " not found. Please ensure the file is on the classpath" );
}
Properties properties = new Properties();
properties.load(url.openStream());

Using Weblogic JWSC Ant task with Maven

March 17, 2009

This post has been moved to here.


Regular expression to remove empty tags

March 13, 2009

Some times is useful to remove empty tags in a given XML. Bellow goes a regular expression to find these empty tags, so that you can replace it by empty.

<.*/>

Why I prefer JUnit 3 over JUnit 4

March 10, 2009

JUnit 4 has many nice features, you can use annotations to configure test methods, to set the methods that should run before them (fka. setUp), etc.

But when I think better about it, I realize that I’ve never had the need, for example, to break my setUp method. If my setUp method grows I suspect of my class or my test being too complicated.

Furthermore, configuration seems extra work to do, so I prefer to stick with old JUnit 3 convention.

JUnit 3 is simple and works. Some times conventions just fits.

I would make a change in JUnit, though. It would be interesting if it called all public methods, so no conventional name nor configuration where necessary.


Build-time weaving with @Configurable and Eclipse

February 2, 2009

@Configurable is a very nice Spring 2.x feature that enables rich domain models with ORM tools like hibernate. I expect to expand on rich domains in a next post. For now I will explain how to use @Configurable.

@Configurable uses AspectJ aspects in order to inject dependencies in non managed classes, I mean, classes that aren’t instantiate by spring but directly by the programmer (with operator new) or by a ORM framework.

There are two ways to enable AspectJ aspects. Run-time weaving (usually requires a special agent attached to the VM) and build-time weaving (no special configuration on the server required).

For build-time weaving AspectJ makes available a ant task that can be used along with eclipse.

Here goes a example:


<project name="aspectwaving" default="compile" >
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
<classpath>
<pathelement location="lib/aspectjtools.jar"/>
</classpath>
</taskdef>

<target name="compile" >
<!-- destDir: output folder. Xlingwarning, showWeaveInfo: detailed information about weaving -->
<iajc destDir="build/classes/" Xlintwarnings="true" showWeaveInfo="true" aspectPath="lib/spring-aspects.jar" debug="true">
<inpath>
<!-- Pathelement: output folder followed by the package containing the classes to be weaved -->
<pathelement location="build/classes/com/mycompany"/>
</inpath>
<classpath>
<!-- JARs the target classes depend upon -->
<pathelement location="lib/aspectjrt.jar"/>
<pathelement location="lib/spring.jar"/>
</classpath>
</iajc>
</target>
</project>

aspectjtools.jar and aspectjrt.jar comes with AspectJ distribution. spring-aspects.jar come with Spring distribution.

To integrate with Eclipse, select project properties -> builders -> new -> ant build and select the build file as shown in the example above.

This aproach has few drawbacks:

  • Eclipse don’t always runs the weaving when using “build automatically” option. A clean/build should resolve the problem.
  • If you don’t use “build automatically” option, each build will take extra five seconds for the weaving process. This is bad when using small development cycles like TDD.

If the problems above bother you, you may use AJDT instead.

More info about configurable and rich domains can be found here:

Anemic Domain Models

Migrating to Spring 2: Part 3 – injecting dependencies into entities


Changing soap version of Spring-WS client

January 28, 2009

This post has been moved to here.


Improving eclipse content assist

January 23, 2009

When I moved from microsoft development to java development I really missed one thing, visual assist.

For the ones not familiar with, visual assist is a add-in to visual studio that enhances content assist and syntax highlighting. The major plus of visual assist is that you don’t have to press ctrl+space all the time, instead it comes with suggestions as you type, so many times all you have to do is type two characters and press enter. No ctrl+space, no typing the whole word.

After a long search I found a feature request for this and a plugin called hyper assist that triggers content assist automatically as you type. Is not as smart as visual assist, but is a good help.

Just download it here and unpack in eclipse plugin folder. To activate press ctrl-alt-shif+Z.