Archive for the ‘java’ Category

When does Ivy:deliver not replace dynamic revisions?

Saturday, March 28th, 2009

When publishing a module, Ivy:deliver (and in turn, publish) has the ability to replace dynamic dependency revisions (e.g. ranges like “2.5+”) with the specific revisions resolved. One thing that is not very obvious is that, since the task relies on the latest resolve results to figure out what exactly those dynamic revisions are resolved to, if the latest resolve is a partial one – meaning only some of the confs are resolved, ivy:deliver may not be able to see all the resolved revisions.

I discovered this when I changed my build script to only resolve ‘master’ before publishing a snapshot to a local repo, because I wanted local publishes to be extremely fast. I guess it’s ok for local snapshots to carry dynamic revisions, but it’s probably a good idea to always do a full resolve before publishing a release.

An Ant Task to Maintain Eclipse Classpaths with Ivy Resolve Results

Friday, February 13th, 2009

I put together an Ant task(download) that can use the result of the ivy:resolve task to maintain Eclipse’s .classpath file. If your ivy:resolve also generates references to the source jars, this task will also attach them to the corresponding classpath entries in the .classpath file. more…

Fix broken maven-metadata.xml through Nexus

Saturday, January 17th, 2009

The log4j maven-metadata.xml hosted at ibiblio is missing the latest two versions, 1.1.14 and 1.1.15. It becomes a problem for me as an Ivy user, too, since Ivy 2.0 adds the ability to use maven metadata to list available versions.

Fortunately I have a Nexus repository as the aggregator/proxy to all the external repositories. Brian from the Nexus IRC room pointed me to this solution/workaround: add the fixed maven-metadata.xml to a repo hosted by Nexus – e.g., the “3rd Party” repo coming out of box in Nexus. Then create a group to aggregate the 3rd Party and the public Ibiblio repos. The “virtual” group repo will automatically create a merged maven-metadata.xml on the fly whenever it is requested.

And it works like a charm. Thanks, Brian!

Hibernate more picky on character type discriminators

Thursday, November 20th, 2008

On a project I’m working on, I’ve got one abstract base class and two subclasses, which are mapped to one same table, with a single character column as the discriminator. I got this error when Hibernate initializes:

org.hibernate.MappingException: multiple or zero characters found parsing string

Turns out if the discriminator type is “character”, the base class must have a discriminator-value attribute declared, even though obviously due to the abstractness there will never be any row carrying that discriminator value. And apparently for “string” type discriminators, there isn’t such a limitation.

How To Upgrade The Freemarker Jar Bundled In JBoss Freemarker IDE

Saturday, August 30th, 2008

The current version (1.0.0.GA) of Freemarker IDE from JBoss Tools comes with freemarker-2.3.8.jar bundled. To update to freemarker 2.3.13:

  1. Copy freemarker-2.3.13.jar into $ECLIPSE_INSTALLATION/plugins/org.jboss.ide.eclipse.freemarker_1.0.0.GA, and remove the freemarker-2.3.8.jar in there.
  2. Edit META-INF/MANIFEST.MF to replace the reference to “freemarker-2.3.8.jar” with “freemarker-2.3.13.jar”.
  3. Restart Eclipse with the “-clean” command line option. This is important because otherwise the Eclipse OSGI engine will keep using cached bundle data which is stale now.

The UnknownHostException and A Not-so-obvious Cause

Monday, June 9th, 2008

The past week has turned out to be the week of “all sorts of weird problems” for me. One of the issues I ran into was that, in a new Ubuntu installation, maven fails to download artifacts from the repository server. After some arm-twisting with maven (people really should start logging the actually exception instead of just printing “unable to download artifact…”), I was able to pinpoint the underlying problem to be an UnknownHostException from trying to resolve the repository server. The strangeness of the situation is, I can access the repo and download the same artifact with firefox, wget, or anything non-java. I can also resolve the repo server name just fine with nslookup. more…

Ivy 2 beta 2 Adds Maven Metadata Support

Tuesday, March 18th, 2008

Ivy 2.0 beta 2 adds an interesting useMavenMetaData switch to its ibiblio resolver. When it’s on (the default actually), Ivy will try and use the maven-metadata.xml for listing the versions available, and for dynamic dependency resolution. This is interesting to me because it makes it a lot easier to run our builds against a proxy repository server like Maven Proxy or Archiva.

Until beta 2, Ivy finds out about the available versions of a module by parsing the directory listing HTML from Ibiblio’s Apache server. That doesn’t work when there is a proxy server sitting in between, because a) the proxy server doesn’t usually proxy directory listing requests, and/or b) the proxy server renders the directory listing in different HTML. Switching to using the structured maven meta data completely eliminated this mess.

Of course, using the maven-metadata.xml files from the official ibiblio repository will subject us to some new hazard – some modules have out-of-date maven-metadata.xml. For instance, by its maven-metadata.xml, the latest version of Hibernate would still be 3.2.0.cr1.

One of those maven proxy servers turns out to be a perfect solution to this problem – we can use them now, remember? :) In my case, I run an Archiva server proxying the official maven 2 repository. Whenever I run into a bad metadata file, I simply request the missing version through Archiva, and it will fetch it and update the metadata file. For example, in the hibernate case, I would just open up Firefox and try to download http://archiva-server/repository/internal/org/hibernate/hibernate/3.2.6.ga/hibernate-3.2.6.ga.jar. That only needs to be done once, and afterwards Archiva would have updated its local version of the maven-metadata.xml properly.

Could Java 7 Please Add A Subpackage Access Modifier?

Sunday, January 6th, 2008

As we all know, the package hierarchy in Java is a rather superficial one. Package com.foo.pack.sub means nothing special to package com.foo.pack – no more special than com.bar.whatever. It’s something that’s seemingly trivial, but really has been discouraging proper organization of classes and more careful design practices. more…

Spring 2.5′s Unintrusive Annotation-based Configuration

Wednesday, November 14th, 2007

Annotation-based configuration isn’t new, but Spring 2.5 adds an interesting twist to it by making it possible to use annotations for wiring, yet without being explicitly tied to any Spring classes. more…

Log4j 1.2.15: What’s With All These Dependencies?

Wednesday, September 19th, 2007

I may not necessarily agree with Weiqi Gao’s opinion that Log4j Must Die, but I have to admit that I really think the new mandatory dependencies added by log4j 1.2.15 are going over the board. To add insult to injury, some of those dependencies – namely com.sun.jdmk.jmxtools and com.sun.jmx.jmxri – aren’t actually available in any public repository due to license reasons. more…