Wednesday, August 02, 2006

Maven2 mysteries

I am at a phase where I can actually experiment with a non-ant build system for a java with other tools (including a lisp based code generator) project.

One of the key requirements is to do very modular development with modules depending on other modules only in a binary way: that is the build system must build the dependency modules if necessary and place the binary deliverables of those modules into classpath or some such thing for any module.

I thougt maven is a good idea and it still seems so ...

Downloaded maven2 (version 2.0.4) based on advice at their web site. Also downloaded "maven 2.0.4 tasks for ant" thinking I might need them and placed it into the lib folder of maven installation. I still think I need them, but read on ...

Then I launched something like:

/cygdrive/d/projects >mvn archetype:create -DgroupId=org.bar -DartifactId=foo -DarchetypeArtifactId=maven-archetype-quickstart


And duly received the following exception:

[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org.apache.maven.profiles.ProfileManager.loadSettingsProfiles(Lorg/apache
/maven/settings/Settings;)V
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NoSuchMethodError: org.apache.maven.profiles.ProfileManager.loadSettingsProfiles(Lorg/apache/maven/settings/Settings;)V
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:273)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------


I must say I was not expecting this behaviour. I wasted like 3-4 hours doing google search, nopes no help (and hence this blog - in case you happen to search for it).

After some frustration and contemplation on whether I should give up etc, I noticed the error carefully. It struck me (obviously based on past experience) that may be there is a problem with the class in that the class does not precisely look like it was supposed to. that is the loading class expects the loaded class to look different.

Then I launched a small handy tool which I use to locate classes : the tool is a shell script that looks like this

root_dir="$1"
substring="$2"

if [ -z "$substring" ]
then
substring="$root_dir"
root_dir="."
fi

if [ -z "$substring" ]
then
cat <<EOS
Usage $0 [root-to-search-from] search-string.
root-to-search-from is optional - defaults to .
The search-string can even hold parts of the package structure
EOS
exit 1
fi

substring=`echo $substring|tr '.' '/'`

old_pwd="`pwd`"
cd "$root_dir"
for j in `find . -name '*.jar' -print`
do
echo "--- $j -------"
jar tvf $j | grep $substring | sed -e 's/^.* //'
echo "++++++++++++++"
done
cd "$old_pwd"



The launch results looked like

.../maven-2.0.4 >find-class ProfileManager
--- ./core/boot/classworlds-1.1.jar -------
++++++++++++++

--- ./lib/maven-artifact-ant-2.0.4-dep.jar -------
org/apache/maven/profiles/DefaultProfileManager.class
org/apache/maven/profiles/ProfileManager.class
++++++++++++++
--- ./lib/maven-artifact-manager-2.0.4.jar -------
++++++++++++++

--- ./lib/maven-project-2.0.4.jar -------
org/apache/maven/profiles/DefaultProfileManager.class
org/apache/maven/profiles/ProfileManager.class
++++++++++++++

.../maven-2.0.4 >


Ah! There are two implementations of ProfileManager.

I nuked maven-artifact-ant-2.0.4-dep.jar from the lib directory and then the project got created peacefully.

Now, is that jar required? May be, who knows?

1 Comments:

Anonymous Anonymous said...

You had to put it in the lib folder of Ant, not Maven

10:54 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home