Wednesday, May 23, 2007

Maven 2.0.6 Installation and proxy configuration

I ran into a very annoying situation while installing Maven 2.0.6 where the document I was following suggested running the following command as part of its quasi tutorial chapter:
  mvn archetype:create
-DarchetypeGroupId=org.apache.maven.archetypes
-DgroupId=com.mycompany.app
-DartifactId=my-app
 

After running it I was greeted with this jewel :

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ----------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ----------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exist
or no valid version could be found
[INFO] ----------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed May 23 12:11:05 CDT 2007
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------


 

Never mind the part of the message suggesting to re-run using the -e switch. The suggestion to do so is really another waste of time offering no new insight as to the real nature of the error. (Typical of error messages, right?)

The appropriate error message required here for me would actually need to read like this:

"Hey, stupid! Maven is a build tool requiring an unfettered internet connection so that it can obtain resource files on an 'as needed' basis, sort of like a Just In Time (JIT) inventory system where parts are ordered as needed. What this means (in spite of what you may have read in the docs) is that you need to copy the settings.xml into your system's home directory.

That in turn means your settings.xml file should be located inside the ~/.m2/directory, where ~ is the current user's home. So on Windows that directory path should resemble c:\documents and settings\\ and on UNIX/Linux it's /home/."

While trying hard (and failing) to stay as far away from the topic of meaningful error messages, (without the insults.. ok, maybe benign ones here and there.) there's still a bit more information required here.

The settings.xml file that comes with Maven is in itself ineffective. This is because 99% of it is commented-out. So rather than deal with a large file, use this version for starters and change to match your environment.

First, notice the reference to the local repository. Yep, Maven needs that location. That's where it's going to place those things the absence of which prevent Maven from working. You can see it below and see the newly added contents created by Maven when I finally fixed this problem.



Second are the entries describing the proxy server name and its port. If you can't determine the name of the proxy server you will need to talk with your company's LAN personnel. Of note is the fact that user id and password are not required as hinted at by the related entries in the ship-with version of settings.xml. In my case, I didn't need them.

With this done, and relying on the fact that you have no other issues falling outside the scope of this post, when you rerun the "mvn archetype:create ... " command you should now be greeted with a list like the one I got, below.



C:\>mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for updates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/1.0-alpha-4/maven-archetype-plugin-1.0-alpha-4.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype/1.0-alpha-4/maven-archetype-1.0-alpha-4.pom
2K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/1/maven-parent-1.pom
6K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/apache/1/apache-1.pom
3K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/1.0-alpha-4/maven-archetype-plugin-1.0-alpha-4.jar
9K downloaded
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] ----------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype-core/1.0-alpha-4/maven-archetype-core-1.0-alpha-4.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-velocity/1.1.2/plexus-velocity-1.1.2.pom
7K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-7/plexus-container-default-1.0-alpha-7.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-containers/1.0.2/plexus-containers-1.0.2.pom
471b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-root/1.0.3/plexus-root-1.0.3.pom
5K downloaded
Downloading: http://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom
145b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.2/plexus-utils-1.0.2.pom
740b downloaded
Downloading: http://repo1.maven.org/maven2/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.pom
3K downloaded
Downloading: http://repo1.maven.org/maven2/commons-collections/commons-collections/2.0/commons-collections-2.0.pom
171b downloaded
Downloading: http://repo1.maven.org/maven2/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.pom
168b downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.pom
2K downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-dep-1.4.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.pom
767b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus/1.0.4/plexus-1.0.4.pom
5K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-model/2.0/maven-model-2.0.pom
2K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven/2.0/maven-2.0.pom
8K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.pom
6K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-artifact-manager/2.0/maven-artifact-manager-2.0.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-repository-metadata/2.0/maven-repository-metadata-2.0.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-artifact/2.0/maven-artifact-2.0.pom
723b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
7K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/wagon/wagon-provider-api/1.0-alpha-5/wagon-provider-api-1.0-alpha-5.pom
4K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-containers/1.0.3/plexus-containers-1.0.3.pom
492b downloaded
Downloading: http://repo1.maven.org/maven2/dom4j/dom4j/1.6.1/dom4j-1.6.1.pom
6K downloaded
Downloading: http://repo1.maven.org/maven2/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.pom
365b downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype-creator/1.0-alpha-4/maven-archetype-creator-1.0-alpha-4.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype-model/1.0-alpha-4/maven-archetype-model-1.0-alpha-4.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-project/2.0/maven-project-2.0.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-profile/2.0/maven-profile-2.0.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-5/plexus-archiver-1.0-alpha-5.pom
439b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-components/1.1.4/plexus-components-1.1.4.pom
2K downloaded
Downloading: http://repo1.maven.org/maven2/oro/oro/2.0.8/oro-2.0.8.pom
140b downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.pom
601b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.2/plexus-utils-1.0.2.jar
156K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype-creator/1.0-alpha-4/maven-archetype-creator-1.0-alpha-4.jar
21K downloaded
Downloading: http://repo1.maven.org/maven2/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar
306K downloaded
Downloading: http://repo1.maven.org/maven2/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
25K downloaded
Downloading: http://repo1.maven.org/maven2/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar
106K downloaded
Downloading: http://repo1.maven.org/maven2/oro/oro/2.0.8/oro-2.0.8.jar
63K downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-dep-1.4.jar
505K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype-core/1.0-alpha-4/maven-archetype-core-1.0-alpha-4.jar
22K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-5/plexus-archiver-1.0-alpha-5.jar
129K downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.jar
352K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-velocity/1.1.2/plexus-velocity-1.1.2.jar
7K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetype/maven-archetype-model/1.0-alpha-4/maven-archetype-model-1.0-alpha-4.jar
15K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
164K downloaded
Downloading: http://repo1.maven.org/maven2/commons-collections/commons-collections/2.0/commons-collections-2.0.jar
88K downloaded
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] **************************************************************
[INFO] Starting Jakarta Velocity v1.4
[INFO] RuntimeInstance initializing.
[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[INFO] ClasspathResourceLoader : initialization starting.
[INFO] ClasspathResourceLoader : initialization complete.
[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
[INFO] Default ResourceManager initialization complete.
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[INFO] Created: 20 parsers.
[INFO] Velocimacro : initialization starting.
[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader.
[INFO] Velocimacro : error using VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'VM_global_library.vm'
[INFO] Velocimacro : VM library template macro registration complete.
[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates
[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
[INFO] Velocimacro : initialization complete.
[INFO] Velocity successfully started.
[INFO] [archetype:create]
[INFO] Defaulting package to group ID: com.mycompany.app
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar
4K downloaded
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating Archetype: maven-archetype-quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.mycompany.app
[INFO] Parameter: packageName, Value: com.mycompany.app
[INFO] Parameter: basedir, Value: C:\
[INFO] Parameter: package, Value: com.mycompany.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: my-app
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] Archetype created in dir: C:\my-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10 seconds
[INFO] Finished at: Wed May 23 11:38:57 CDT 2007
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------


 

Now go visit your Maven repository and note the addition of new directories.

In addition, you should see a new project directory resembling this one.

No comments: