How do I create a project with an archetype I've created?
Author: Deron Eriksson
Description: This maven tutorial describes how to create a project with an archetype that you've created.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


Page:    1 2 >

In another tutorial, we used maven-archetype-archetype to create an archetype project called "maven-archetype-example" and we installed that project in the local mavenSW repository. We can now use that archetype to create project. This short tutorial will demonstrate this.

I created an EclipseSW external tool configuration to execute the maven archetype:create goal, with the new archetype specified using -D flags.

Name:mvn archetype~create example
Location:${maven_exec}
Working Directory:${workspace_loc}
Arguments:archetype:create -DgroupId=${string_prompt:groupId} -DartifactId=${string_prompt:artifactId} -DarchetypeArtifactId=maven-archetype-example -DarchetypeGroupId=com.myarchetype -DarchetypeVersion=1.0-SNAPSHOT

The external tool configuration is shown here:

External Tool Configuration

When I run the configuration, I'm prompted for the groupId for the new project. I enter "com.maventest".

Entering groupId

I call the project "anotherproject".

Entering artifactId

The console output of the maven command is shown here:

Console output for 'mvn archetype:create -DgroupId=com.maventest -DartifactId=anotherproject -DarchetypeArtifactId=maven-archetype-example -DarchetypeGroupId=com.myarchetype -DarchetypeVersion=1.0-SNAPSHOT'

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[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.maventest
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating Archetype: maven-archetype-example:1.0-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.maventest
[INFO] Parameter: packageName, Value: com.maventest
[INFO] Parameter: package, Value: com.maventest
[INFO] Parameter: artifactId, Value: anotherproject
[INFO] Parameter: basedir, Value: C:\dev\workspace
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] Archetype created in dir: C:\dev\workspace\anotherproject
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Feb 20 16:49:54 PST 2008
[INFO] Final Memory: 5M/9M
[INFO] ------------------------------------------------------------------------

The project has been created in my Eclipse workspace directory in the file system. Now it needs to be imported into Eclipse. To do this, in my Navigator view I select New → Project.

New Project

I select JavaSW Project.

Java Project

I locate the project in the file system and I specify the name "anotherproject" and click Finish.

Create project from existing source

The "anotherproject" project can now be seen in Eclipse. I'll perform a "mvn eclipse:eclipse" on "anotherproject" to fix the classpathW.

Executing 'mvn eclipse:eclipse' on 'anotherproject'

The target directory has been created by eclipse:eclipse. I'll delete the bin directory since it is no longer needed.

'anotherproject' in Eclipse Navigator View

The "anotherproject" project is now ready to work on. In this project, we see the expected pom.xml file, App.java file, and AppTest.java file.

'anotherproject' structure

(Continued on page 2)

Page:    1 2 >