malachi@onyx:~/work/archtest$ treeNothing fancy here. Standard standalone app.
.
|-- pom.xml
`-- src
`-- main
`-- java
`-- org
`-- eoti
`-- archtest
|-- Test1.java
`-- Test2.java
6 directories, 3 files
Make sure it all compiles (mvn clean install). Typos are much easier to fix at this stage. If you want specific repositories or dependencies to be included by default in applications, make sure to include those in your pom now.
Once it has built successfully, let's build our initial archetype (mvn clean archetype:create-from-project).
If all went well, your directory tree should be quite a bit bigger now:
malachi@onyx:~/work/archtest/target/generated-sources/archetype$ treeYour initial project (though modified) is still buried in there:
.
|-- pom.xml
|-- src
| |-- main
| | `-- resources
| | |-- archetype-resources
| | | |-- pom.xml
| | | `-- src
| | | `-- main
| | | `-- java
| | | |-- Test1.java
| | | `-- Test2.java
| | `-- META-INF
| | `-- maven
| | `-- archetype-metadata.xml
| `-- test
| `-- resources
| `-- projects
| `-- basic
| |-- archetype.properties
| `-- goal.txt
`-- target
|-- archtest-archetype-1.0-SNAPSHOT.jar
|-- classes
| |-- archetype-resources
| | |-- pom.xml
| | `-- src
| | `-- main
| | `-- java
| | |-- Test1.java
| | `-- Test2.java
| `-- META-INF
| `-- maven
| `-- archetype-metadata.xml
`-- test-classes
`-- projects
`-- basic
|-- archetype.properties
`-- goal.txt
24 directories, 14 files
malachi@onyx:~/work/archtest/target/generated-sources/archetype/src/main/resources/archetype-resources$ treeLook through that subset of files. You'll notice that the pom.xml has changed the groupId, artifactId and version to be variables. You'll also notice that Test1.java and Test2.java are no longer listed under a specific package directory structure. You will also notice that both .java files have a variable package declaration.
.
|-- pom.xml
`-- src
`-- main
`-- java
|-- Test1.java
`-- Test2.java
3 directories, 3 files
Let's go ahead and install our new archetype locally. Go into target/generated-sources/archetype and build it (mvn clean install).
Assuming all went well, let's give it a shot:
malachi@onyx:~/work$ mvn archetype:generate -DarchetypeGroupId=org.eoti.archtest -DarchetypeArtifactId=archtest-archetype -DarchetypeVersion=1.0-SNAPSHOTIt will prompt you to fill in some values:
Define value for property 'groupId': : org.eoti.test.archetypetest
Define value for property 'artifactId': : ArchetypeTest
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': org.eoti.test.archetypetest: :
Confirm properties configuration:
groupId: org.eoti.test.archetypetest
artifactId: ArchetypeTest
version: 1.0-SNAPSHOT
package: org.eoti.test.archetypetest
Y: :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.650s
[INFO] Finished at: Thu Apr 28 12:07:37 PDT 2011
[INFO] Final Memory: 8M/245M
[INFO] ------------------------------------------------------------------------
malachi@onyx:~/work$ tree ArchetypeTest/
ArchetypeTest/
|-- pom.xml
`-- src
`-- main
`-- java
`-- org
`-- eoti
`-- test
`-- archetypetest
|-- Test1.java
`-- Test2.java
7 directories, 3 files
You will see that all your variables have been replaced with the values you were prompted to fill in. You now have a working archetype =)
No comments:
Post a Comment