Version 12.1 by Lachlan Deck on 2008/06/15 18:39

Hide last authors
Lachlan Deck 5.1 1 So you're interested in //kicking the maven tyres//, so to speak, or just want to see what it's all about. The following provides hints on how to try maven with your current WebObjects projects, if say you're using the standard WOLips ant builds, without having to adopt a different file structure. Whilst this is not the recommended approach for the long term it allows you to try things out side-by-side with your current build system.
2
3 {{info title="Recommended Homework (or pre-requisites)"}}
4
Lachlan Deck 12.1 5 It's _really_ worth doing your homework on maven in order to understand it. The place to start is Learning Maven found at http://maven.apache.org. Various guides are also found at http://maven.apache.org/guides/.
Lachlan Deck 5.1 6
7 At the very least you want to have read through, and understood, the [Getting Started Tutorial|http://maven.apache.org/guides/getting-started/index.html].
8
9 The maven user mailing list is also recommended for getting help. It's quite active and, as you find for the WebObjects mailing lists, is an invaluable resource. See [Getting Help|http://maven.apache.org/users/getting-help.html].
10
11 {{/info}}
12
Lachlan Deck 12.1 13 === What's the aim ===
Lachlan Deck 5.1 14
Lachlan Deck 12.1 15 This might be stating the obvious, but an OO developer will, in the course of time (or is //supposed// to anyway), build up various encapsulated, //reusable//, libraries or frameworks that can be tapped into for differing projects. So let's assume we have multiple frameworks and applications in our build. Each of these has some common ground, such as their dependencies on certain WebObjects frameworks, or the file layout, and of course they each may have something distinctive about them.
Lachlan Deck 5.1 16
17 The layout of the frameworks and applications might look like this:
18
19 {{noformat}}
20
21 /trunk/
22 /trunk/apps/
23 /trunk/apps/ApplicationA/
24 /trunk/apps/ApplicationB/
25 /trunk/frameworks/
26 /trunk/frameworks/CustomExtensions/
27 /trunk/frameworks/CustomBusinessLogic/
28 /trunk/frameworks/etc/
29
30 {{/noformat}}
31
Lachlan Deck 12.1 32 Our aim is twofold:
Lachlan Deck 5.1 33
Lachlan Deck 12.1 34 1. put as much configuration as possible that's shared between all frameworks, for example, into /frameworks/pom.xml so we only have to define it once. The configuration is inherited by a child pom.
Lachlan Deck 5.1 35 1. Be able to issue a single command that will package each and every framework and application.
36
37 === Key Concepts ===
38
39 Typical things that make up a pom are as follows. (Note: only pom identification is mandatory. All the others have defaults.)
40
41 1. pom identification (who am I?)
Lachlan Deck 12.1 42 The base triplet used to identify an artifact (i.e., product)
43 {{noformat}}
Lachlan Deck 5.1 44 <artifactId>CustomExtensions</artifactId>
45 <groupId>com.mywostuff.frameworks</groupId>
46 <version>0.0.1-SNAPSHOT</version>
Lachlan Deck 12.1 47 {{/noformat}}
Lachlan Deck 5.1 48 1. pom packaging (i.e., what are we building?)
Lachlan Deck 12.1 49 The default value for the packaging element is JAR if not specified. For the purposes of this exercise, we'll use JAR for the frameworks and woapplication for the applications, which requires the woproject maven plugin (TODO revisit this scenario with the apple maven plugin)
50 {{noformat}}
Lachlan Deck 5.1 51 <packaging>woapplication</artifactId>
Lachlan Deck 12.1 52 {{/noformat}}
Lachlan Deck 5.1 53 1. pom parent identification (who do I belong to?)
Lachlan Deck 12.1 54 {{noformat}}
Lachlan Deck 5.1 55 <parent>
56 <artifactId>frameworks</artifactId>
57 <groupId>com.mywostuff</groupId>
58 </parent>
Lachlan Deck 12.1 59 {{/noformat}}
Lachlan Deck 5.1 60 1. modules (a.k.a kids; who belongs to me?)
Lachlan Deck 12.1 61 {{noformat}}
Lachlan Deck 5.1 62 <modules>
63 <module>CustomExtensions</module>
64 <module>CustomBusinessLogic</module>
65 </modules>
Lachlan Deck 12.1 66 {{/noformat}}
Lachlan Deck 5.1 67 1. dependencies (what do I need?)
Lachlan Deck 12.1 68 {{noformat}}
Lachlan Deck 5.1 69 <dependencies>
70 <dependency>
71 <groupId>log4j</groupId>
72 <artifactId>log4j</artifactId>
73 <version>1.2.12</version>
74 <scope>compile</scope>
75 </dependency>
76 <dependency>
77 <groupId>junit</groupId>
78 <artifactId>junit</artifactId>
79 <version>4.4</version>
80 <scope>test</scope>
81 </dependency>
82 </dependencies>
Lachlan Deck 12.1 83 {{/noformat}}
Lachlan Deck 5.1 84 1. build sources/resources (what do I have?)
85 1. properties and filtering resources (variable definitions)
86 1. dependency/plugin management (shared configuration and versioning)
87 1. repositories (where to find dependencies and plugins)
88
Lachlan Deck 12.1 89 Of course, with the plethora of plugins available for maven, this is only the tip of the iceberg. However, these main concepts will suffice for now.
Lachlan Deck 5.1 90
91 === Alternate File System Layout Concepts ===
92
93 As you would (i.e., should) have read by now, Maven has what it calls //standards//. One such standard is the [[standard directory layout>>http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html_standard]]. One of the advantages of following the standards is that you get something for free: you have less to configure (or even almost nothing) in order to build a jar, for example, from your sources and resources. When that's not possible, options are available that allow you to //subvert// these standards or provide extra resouces.
94
95 {{tip title="Mavan Model Reference Doco"}}
96
97 To see what built-in options are available for maven see [Maven Model|http://maven.apache.org/ref/2.0.9/maven-model/maven.html].
98
99 {{/tip}}
100
Lachlan Deck 12.1 101 The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout).
Lachlan Deck 5.1 102
103 {{noformat}}
104
105 /MyProject
106 /MyProject/Components
107 /MyProject/Resources
108 /MyProject/Sources
109 /MyProject/Tests
110 /MyProject/WebServerResources
111
112 {{/noformat}}
113
Lachlan Deck 12.1 114 Assuming your building a framework, for example, the following is an extract from the relevant pom.xml. It specifies where to find your java source files and resources. Notice we've also defined the target path for each resource. (See the [[Maven Model#class//resource//>>http://maven.apache.org/ref/2.0.9/maven-model/maven.html#class_resource]] for a definition of targetPath)
Lachlan Deck 5.1 115
116 {{code title="pom.xml"}}
117
118 <...>
119 <build>
120 <sourceDirectory>Sources</sourceDirectory>
121 <testSourceDirectory>Tests</testSourceDirectory>
122 <resources>
123 <resource>
124 <targetPath>Resources</targetPath>
125 <filtering>false</filtering>
126 <directory>Components</directory>
127 </resource>
128 <resource>
129 <targetPath>Resources</targetPath>
130 <filtering>false</filtering>
131 <directory>Resources</directory>
132 </resource>
133 <resource>
134 <targetPath>WebServerResources</targetPath>
135 <filtering>false</filtering>
136 <directory>WebServerResources</directory>
137 </resource>
138 </resources>
139 <...>
140 </build>
141 <...>
142
143 {{/code}}
144
145 So, concentrating on our frameworks alone for the moment, assuming all of your frameworks share the above project layout the above can happily go into your /frameworks/pom.xml file and as such be shared by all sub-modules (i.e., frameworks).
146
147 === Project Dependencies Concepts ===
148
Lachlan Deck 12.1 149 Most projects, of course, have dependencies on other libraries or frameworks.
Lachlan Deck 5.1 150
Lachlan Deck 12.1 151 === Project Dependencies Prerequisites ===
Lachlan Deck 5.1 152
Lachlan Deck 12.1 153 details to come...
Lachlan Deck 5.1 154
155 === Packaging Frameworks as Jars ===
156
Lachlan Deck 12.1 157 details to come...
Lachlan Deck 5.1 158
159 === Packaging Applications ===
160
Lachlan Deck 12.1 161 details to come...
Lachlan Deck 5.1 162
Lachlan Deck 12.1 163 === Project Inheritance ===
Lachlan Deck 5.1 164
Lachlan Deck 12.1 165 details to come...
Lachlan Deck 5.1 166
167 === Eclipse Integration ===
168
169 details to come...
170
171 === Putting It All Together ===
172
173 details to come...