Version 5.1 by Lachlan Deck on 2008/06/23 18:51

Show last authors
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
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/].
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
13 === What's the aim ===
14
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.
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
32 Our aim is twofold:
33
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.
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?)
42 The base triplet used to identify an artifact (i.e., product)
43
44 {{noformat}}
45
46 <artifactId>CustomExtensions</artifactId>
47 <groupId>com.mywostuff.frameworks</groupId>
48 <version>0.0.1-SNAPSHOT</version>
49
50 {{/noformat}}
51
52 1. pom packaging (i.e., what are we building?)
53 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)
54
55 {{noformat}}
56
57 <packaging>woapplication</artifactId>
58
59 {{/noformat}}
60
61 1. pom parent identification (who do I belong to?)
62
63 {{noformat}}
64
65 <parent>
66 <artifactId>frameworks</artifactId>
67 <groupId>com.mywostuff</groupId>
68 </parent>
69
70 {{/noformat}}
71
72 1. modules (a.k.a kids; who belongs to me?)
73
74 {{noformat}}
75
76 <modules>
77 <module>CustomExtensions</module>
78 <module>CustomBusinessLogic</module>
79 </modules>
80
81 {{/noformat}}
82
83 1. dependencies (what do I need?)
84
85 {{noformat}}
86
87 <dependencies>
88 <dependency>
89 <groupId>log4j</groupId>
90 <artifactId>log4j</artifactId>
91 <version>1.2.12</version>
92 <scope>compile</scope>
93 </dependency>
94 <dependency>
95 <groupId>junit</groupId>
96 <artifactId>junit</artifactId>
97 <version>4.4</version>
98 <scope>test</scope>
99 </dependency>
100 </dependencies>
101
102 {{/noformat}}
103
104 1. build sources/resources (what do I have?)
105 1. properties and filtering resources (variable definitions)
106 1. dependency/plugin management (shared configuration and versioning)
107 1. repositories (where to find dependencies and plugins)
108
109 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.
110
111 === Alternate File System Layout Concepts ===
112
113 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.
114
115 {{tip title="Mavan Model Reference Doco"}}
116
117 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].
118
119 {{/tip}}
120
121 The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout).
122
123 {{noformat}}
124
125 /MyProject
126 /MyProject/Components
127 /MyProject/Resources
128 /MyProject/Sources
129 /MyProject/Tests
130 /MyProject/WebServerResources
131
132 {{/noformat}}
133
134 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)
135
136 {{code title="pom.xml"}}
137
138 <...>
139 <build>
140 <sourceDirectory>Sources</sourceDirectory>
141 <testSourceDirectory>Tests</testSourceDirectory>
142 <resources>
143 <resource>
144 <targetPath>Resources</targetPath>
145 <filtering>false</filtering>
146 <directory>Components</directory>
147 </resource>
148 <resource>
149 <targetPath>Resources</targetPath>
150 <filtering>false</filtering>
151 <directory>Resources</directory>
152 </resource>
153 <resource>
154 <targetPath>WebServerResources</targetPath>
155 <filtering>false</filtering>
156 <directory>WebServerResources</directory>
157 </resource>
158 </resources>
159 <...>
160 </build>
161 <...>
162
163 {{/code}}
164
165 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).
166
167 === Project Dependencies Concepts ===
168
169 Most projects, of course, have dependencies on other libraries or frameworks. See the [[Maven Getting Started#How//do//I//use//external//dependencies//>>http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_external_dependencies]].
170
171 The following shows the mixture of third party dependencies and custom framework dependencies. Notice that the scope element determines the life cycle phase each dependency is relevant for. See [[Maven Model#class//dependency//>>http://maven.apache.org/ref/2.0.9/maven-model/maven.html#class_dependency]] for specific definitions.
172
173 {{noformat}}
174
175 <dependencies>
176 <dependency>
177 <artifactId>CustomExtensions</artifactId>
178 <groupId>com.mywostuff.frameworks</groupId>
179 <version>0.0.1-SNAPSHOT</version>
180 <scope>compile</scope>
181 </dependency>
182 <dependency>
183 <groupId>log4j</groupId>
184 <artifactId>log4j</artifactId>
185 <version>1.2.12</version>
186 <scope>compile</scope>
187 </dependency>
188 <dependency>
189 <groupId>junit</groupId>
190 <artifactId>junit</artifactId>
191 <version>4.4</version>
192 <scope>test</scope>
193 </dependency>
194 </dependencies>
195
196 {{/noformat}}
197
198 === Repositories ===
199
200 So far we have assumed that maven just knows where to find third party libraries. There is the default local repository (e.g., ,,/.m2/repository) and a remote one at ibiblio.org or a mirror of the same. See [[http://maven.apache.org/guides/introduction/introduction-to-repositories.html]].,,
201
202 {{noformat}}
203
204 <repositories>
205 <repository>
206 <id>system-repo</id>
207 <name>internal repository</name>
208 <!-- TODO switch over to your intranet.domain -->
209 <url>file://${user.home}/.myarchiva</url>
210 <snapshots>
211 <enabled>true</enabled>
212 <updatePolicy>always</updatePolicy>
213 <checksumPolicy>ignore</checksumPolicy>
214 </snapshots>
215 <releases>
216 <enabled>true</enabled>
217 <updatePolicy>always</updatePolicy>
218 <checksumPolicy>ignore</checksumPolicy>
219 </releases>
220 </repository>
221 <repository>
222 <id>maven2-repository.dev.java.net</id>
223 <name>Java.net Repository for Maven</name>
224 <url>http://download.java.net/maven/2</url>
225 <snapshots>
226 <enabled>true</enabled>
227 <updatePolicy>daily</updatePolicy>
228 </snapshots>
229 <releases>
230 <enabled>true</enabled>
231 <updatePolicy>daily</updatePolicy>
232 </releases>
233 </repository>
234 <repository>
235 <id>webobjects.mdimension.com/releases</id>
236 <name>mdimension maven 2 releases repo</name>
237 <url>http://webobjects.mdimension.com/maven2/releases</url>
238 <snapshots>
239 <enabled>false</enabled>
240 </snapshots>
241 <releases>
242 <enabled>true</enabled>
243 </releases>
244 </repository>
245 <repository>
246 <id>webobjects.mdimension.com/snapshots</id>
247 <name>mdimension maven 2 snapshots repo</name>
248 <url>http://webobjects.mdimension.com/maven2/snapshots</url>
249 <snapshots>
250 <enabled>true</enabled>
251 </snapshots>
252 <releases>
253 <enabled>false</enabled>
254 </releases>
255 </repository>
256 <repository>
257 <id>objectstyle-maven2</id>
258 <name>objectstyle maven2 repo</name>
259 <url>http://objectstyle.org/maven2</url>
260 <snapshots>
261 <enabled>false</enabled>
262 </snapshots>
263 <releases>
264 <enabled>true</enabled>
265 </releases>
266 </repository>
267 </repositories>
268
269 {{/noformat}}
270
271 Note: A remote repository is not guaranteed to keep older versions of libraries, for example, indefinitely. It's recommended that you set up one for your intranet which stores what you need for longevity. See both the above intro to repositories and [[http://www.theserverside.com/tt/articles/article.tss?l=SettingUpMavenRepository]].
272
273 === Packaging Frameworks as Jars ===
274
275 Here's the definition for /frameworks/pom.xml.
276
277 {{code title="/frameworks/pom.xml"}}
278
279 <?xml version="1.0" encoding="UTF-8"?>
280 <project xmlns="http://maven.apache.org/POM/4.0.0"
281 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
282 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
283 http://maven.apache.org/xsd/maven-4.0.0.xsd">
284
285 <modelVersion>4.0.0</modelVersion>
286
287 <!-- parent artifact -->
288 <parent>
289 <artifactId>mywostuff</artifactId>
290 <groupId>com</groupId>
291 <version>1.0-SNAPSHOT</version>
292 </parent>
293
294 <!-- artifact identity -->
295 <artifactId>frameworks</artifactId>
296 <groupId>com.mywostuff</groupId>
297 <packaging>pom</packaging>
298
299 <!-- framework relevant properties -->
300 <properties>
301 <!-- NS related properties fills in Info.plist etc-->
302 <CFBundleDevelopmentRegion>English</CFBundleDevelopmentRegion>
303 <CFBundleGetInfoString></CFBundleGetInfoString>
304 <CFBundlePackageType>FMWK</CFBundlePackageType>
305 <CFBundleIconFile>WOAfile.icns</CFBundleIconFile>
306 <CFBundleInfoDictionaryVersion>6.0</CFBundleInfoDictionaryVersion>
307 <CFBundleVersion>5.3.1</CFBundleVersion>
308 <Has_WOComponents>true</Has_WOComponents>
309 <NSPrincipalClass>${mainclass}</NSPrincipalClass>
310 <NSResourcesBundlePath></NSResourcesBundlePath>
311 </properties>
312
313 <!-- modules -->
314 <modules>
315 <module>CustomExtensions</module>
316 <module>CustomBusinessLogic</module>
317 </modules>
318
319 <!-- specific dependencies (for modules) -->
320 <dependencies>
321 <dependency>
322 <artifactId>ERExtensions</artifactId>
323 <groupId>${wonder.common.groupId}</groupId>
324 </dependency>
325 <dependency>
326 <artifactId>JavaWOExtensions</artifactId>
327 <groupId>${wonder.common.groupId}</groupId>
328 </dependency>
329 <dependency>
330 <artifactId>JavaFoundation</artifactId>
331 <groupId>${webobjects.groupId}</groupId>
332 </dependency>
333 <dependency>
334 <artifactId>JavaJDBCAdaptor</artifactId>
335 <groupId>${webobjects.groupId}</groupId>
336 </dependency>
337 <dependency>
338 <artifactId>JavaWebObjects</artifactId>
339 <groupId>${webobjects.groupId}</groupId>
340 </dependency>
341 <dependency>
342 <artifactId>JavaEOControl</artifactId>
343 <groupId>${webobjects.groupId}</groupId>
344 </dependency>
345 <dependency>
346 <artifactId>JavaEOAccess</artifactId>
347 <groupId>${webobjects.groupId}</groupId>
348 </dependency>
349 <dependency>
350 <artifactId>JavaWebObjects</artifactId>
351 <groupId>${webobjects.groupId}</groupId>
352 </dependency>
353 <dependency>
354 <artifactId>JavaXML</artifactId>
355 <groupId>${webobjects.groupId}</groupId>
356 </dependency>
357 </dependencies>
358
359
360 <!-- build config (for modules) -->
361 <build>
362 <sourceDirectory>src</sourceDirectory>
363 <testSourceDirectory>tests</testSourceDirectory>
364 <resources>
365 <!-- relative dir for Info.plist -->
366 <resource>
367 <targetPath>Resources</targetPath>
368 <filtering>true</filtering>
369 <directory>../src/main/resources</directory>
370 </resource>
371 <resource>
372 <targetPath>Resources</targetPath>
373 <filtering>false</filtering>
374 <directory>Components</directory>
375 </resource>
376 <resource>
377 <targetPath>Resources</targetPath>
378 <filtering>false</filtering>
379 <directory>Resources</directory>
380 </resource>
381 <resource>
382 <targetPath>WebServerResources</targetPath>
383 <filtering>false</filtering>
384 <directory>WebServerResources</directory>
385 </resource>
386 </resources>
387 <plugins>
388 <plugin>
389 <groupId>org.apache.maven.plugins</groupId>
390 <artifactId>maven-compiler-plugin</artifactId>
391 <configuration>
392 <source>${java.target}</source>
393 <target>${java.target}</target>
394 </configuration>
395 </plugin>
396 </plugins>
397 </build>
398 </project>
399
400 {{/code}}
401
402 and CustomExtensions which has no further dependencies
403
404 {{code title="/frameworks/CustomBusinessLogic/pom.xml"}}
405
406 <?xml version="1.0"?>
407 <project>
408 <!-- parent artifact -->
409 <parent>
410 <artifactId>frameworks</artifactId>
411 <groupId>com.mywostuff</groupId>
412 <version>1.0-SNAPSHOT</version>
413 </parent>
414
415 <!-- artifact identity -->
416 <artifactId>CustomBusinessLogic</artifactId>
417 <groupId>com.mywostuff.frameworks</groupId>
418 </project>
419
420 {{/code}}
421
422 and CustomBusinessLogic (which has a further dependency on CustomExtensions)
423
424 {{code title="/frameworks/CustomBusinessLogic/pom.xml"}}
425
426 <?xml version="1.0"?>
427 <project>
428 <!-- parent artifact -->
429 <parent>
430 <artifactId>frameworks</artifactId>
431 <groupId>com.mywostuff</groupId>
432 <version>1.0-SNAPSHOT</version>
433 </parent>
434
435 <!-- artifact identity -->
436 <artifactId>CustomBusinessLogic</artifactId>
437 <groupId>com.mywostuff.frameworks</groupId>
438
439 <!-- specific dependencies -->
440 <dependencies>
441 <dependency>
442 <artifactId>CustomExtensions</artifactId>
443 <groupId>${pom.groupId}</groupId>
444 </dependency>
445 </dependencies>
446 </project>
447
448 {{/code}}
449
450 === Packaging Applications ===
451
452 details to come...
453
454 === Packaging Applications as True WAR ===
455
456 You can find steps to package WO Applications as True WAR [[here>>Packaging WO Applications as true WAR with Maven]].
457
458 more details to come...
459
460 === Project Inheritance ===
461
462 details to come...
463
464 === Eclipse Integration ===
465
466 details to come...
467
468 === Putting It All Together ===
469
470 details to come...