Monday, September 10, 2007

[Java, Maven, Jetspeed-2] Can't build Jetspeed-2 with maven, settings.xml getting me bored

Problem: Maven2 doesn't build my Jetspeed-2 portal with a strange cast exception
Solution: Check %USERPROFILE%/.m2/settings.xml file position

My boss went in my office and said "Ok Scuffia, your time has come! With the mighty power of the holy Apache Ant you will package your application, no matter how nor why, but I want a spelled Ant script that builds all your application need to run!" .

First of all my application is composed by:
  • a Core (a simple Java Library with about 30 classes) that uses 4 other libraries (mainly XML Parsers, loggers, DB accessors)
  • A portal container (Jetspeed-2)
  • At the moment only one portlet (used to access data)
  • A servlet that is an interface between the Core and the Portlet
  • A web service (using Axis 1.x) that exports Core methods (in practice the same functionality as the servlet)
There were no problems to rule Ant scripts as to build the Core library (with all depencencies and all needed configuration files, like .properties files); as my application need to be held in one folder, I decided to put together Ant and all source folders.

I also decided to use Maven to build Jetspeed-2 and all portlets, bacause all installation scripts were already done (building, linking, db creating, and resource copying); Maven uses a local repository, in wich it stores downloaded libraries (from servers whose URL are in the configuration file); as my boss needs a completly "offline" installation, all libraries are supposed to be fully downloaded and ready to be linked. Obiously Maven has its configuration file (under ./mavenFolder/conf/settings.xml) in wich you can set the path to the repository: moreover you can choose a configuration different for each user of your OS (Win XP in my case), putting each configuration file inside %USERPROFILE%/.m2/, wich "overwrites" general settings.

Building the portal was as simple as writing:
mvn -P tomcat,min
that stated to build the portal with the underneath web server Tomcat, with just the portal itself and only the administrative portlets (that help administrator to manage users and portlets).

I was so happy that I knew all to do, that I thought to end the work in just 1 working day (inlcuding neverending breaks!)...but It was not so simple!
Each time I tried to build, I got the same error:
D:\GAPWORKSPACE\jetspeed-portal\gapportal\
etc\build.xml:502: java.lang.ClassCast Exception:
org.apache.maven.usability.MojoExecutionExceptionDiagnoser
cannot be cast to
org.apache.maven.usability.diagnostics.ErrorDiagnoser

It lasted for about 3 working days, with my powerlessness: I followed all errors, trying to change code, reading each Maven building script (O.O), when I saw that, as I was using only ./mavenFolder/conf/settings.xml file because I wanted to have the whole stuff inside the same directory and no other file elsewhere, Maven tried to use anyway %USERPROFILE%/.m2/ directory and, only for some libraries, were looking for them in %USERPROFILE%/.m2/repository/, in wich actually there was nothing...
THIS TOOK ME 3 FUCKING DAYS!!!!!
So, although it is not so nice, I decided to have a copy of settings.xml in the user directory, so maven always knows where the repoository is.
And that's the end of my asshole tragedy.

.Net Butchering (and JAVA messes)

11 comments:

Johnny Idol said...

Open Source MY ASS

Scuffia said...

Open Source is a good thing if you like to spend less time in coding and earn money with less work...but when it works like a bitch no words could be spent for!

Johnny Idol said...

"as my application need to be held in one folder, I decided to put together Ant and all source folders" this sounds like no best practice.
Open Source is less money in tools but more money in workforce in general (ask the guy in the Microsoft advertisement). I like it, but it can be a pain in the ass like when the shit is on.

Scuffia said...

you are right jhonny, in fact open source is the best when it works properly!

Anonymous said...

You Geeks

Matteo said...

OpenSource is a blessing, not a problem. The problem is the large community of butchers out there...

Johnny Idol said...

When you're running out of time, Open source or not, you're gonna unleash the butcher that's in you.
And an open source butcher is worse than a propertary one...

Sam said...

I am having the exact same problem. I am working on Ubuntu. settings.xml file has been overriden as per the jetspeed tutorial. I've read your post more then 5 times but still unable to figure out how you resolved it. Your help would certainly be valuable.

Johnny Idol said...

Hi Sam, I am sure Scuffia will be able to help somehow, he'll be back soon from holidays. Hold on

Scuffia said...

Hi Sam, I don't know wich is in Ubuntu the user directory in wich Maven would look for its setting.xml file. Anyway make a search in google and you will find the unswer (I'm not really practiced with Linux, but it should be something like "usr\.m2\"): simply copy the maven settings.xml file of yout own into this directory (be sure the the URI of your repository directory is correctly spelled inside the setting file).
Bye

Paul said...

This problem still occurs when trying to build a jetspeed portal using the "tomcat" and "min" maven goals!!
I've copied my personal ~/.m2/settings.xml file to /etc/maven2/settings.xml, but I still get the same exception! Scuffia, how did you conclude that the MojoExecutionExceptionDiagnoser was caused by a problem in the global settings.xml file? - being an ant user, I'm new to maven. Any help/suggestions gratefully received!