Version 21.1 by Lachlan Deck on 2008/07/02 23:41

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 {{tip title="Hang in there"}}
14
15 This particular guide might look long but some of the xml is duplicated a few times to show differing examples.
16
17 {{/tip}}
18
19 === What's the aim ===
20
21 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.
22
23 The layout of the frameworks and applications might look like this:
24
25 {{noformat}}
26
27 /trunk/
28 /trunk/apps/
29 /trunk/apps/ApplicationA/
30 /trunk/apps/ApplicationB/
31 /trunk/frameworks/
32 /trunk/frameworks/CustomExtensions/
33 /trunk/frameworks/CustomBusinessLogic/
34 /trunk/frameworks/etc/
35
36 {{/noformat}}
37
38 Our aim is twofold:
39
40 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.
41 1. Be able to issue a single command that will package each and every framework and application.
42
43 === Key Concepts ===
44
45 Typical things that make up a pom are as follows. (Note: only pom identification is mandatory. All the others have defaults.)
46
47 1. pom identification (who am I?)
48 The base triplet used to identify an artifact (i.e., product)
49
50 {{noformat}}
51
52 <artifactId>CustomExtensions</artifactId>
53 <groupId>com.mywostuff.frameworks</groupId>
54 <version>0.0.1-SNAPSHOT</version>
55
56 {{/noformat}}
57
58 1. pom packaging (i.e., what are we building?)
59 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)
60
61 {{noformat}}
62
63 <packaging>woapplication</artifactId>
64
65 {{/noformat}}
66
67 1. pom parent identification (who do I belong to?)
68
69 {{noformat}}
70
71 <parent>
72 <artifactId>frameworks</artifactId>
73 <groupId>com.mywostuff</groupId>
74 </parent>
75
76 {{/noformat}}
77
78 1. modules (a.k.a kids; who belongs to me?)
79
80 {{noformat}}
81
82 <modules>
83 <module>CustomExtensions</module>
84 <module>CustomBusinessLogic</module>
85 </modules>
86
87 {{/noformat}}
88
89 1. dependencies (what do I need?)
90
91 {{noformat}}
92
93 <dependencies>
94 <dependency>
95 <groupId>log4j</groupId>
96 <artifactId>log4j</artifactId>
97 <version>1.2.12</version>
98 <scope>compile</scope>
99 </dependency>
100 <dependency>
101 <groupId>junit</groupId>
102 <artifactId>junit</artifactId>
103 <version>4.4</version>
104 <scope>test</scope>
105 </dependency>
106 </dependencies>
107
108 {{/noformat}}
109
110 1. build sources/resources (what do I have?)
111 1. properties and filtering resources (variable definitions)
112 1. dependency/plugin management (shared configuration and versioning)
113 1. repositories (where to find dependencies and plugins)
114
115 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.
116
117 === Alternate File System Layout Concepts ===
118
119 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.
120
121 {{tip title="Mavan Model Reference Doco"}}
122
123 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].
124
125 {{/tip}}
126
127 The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout).
128
129 {{noformat}}
130
131 /MyProject
132 /MyProject/Components
133 /MyProject/Resources
134 /MyProject/Sources
135 /MyProject/Tests
136 /MyProject/WebServerResources
137
138 {{/noformat}}
139
140 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)
141
142 {{code title="pom.xml"}}
143
144 <...>
145 <build>
146 <sourceDirectory>Sources</sourceDirectory>
147 <testSourceDirectory>Tests</testSourceDirectory>
148 <resources>
149 <resource>
150 <targetPath>Resources</targetPath>
151 <filtering>false</filtering>
152 <directory>Components</directory>
153 </resource>
154 <resource>
155 <targetPath>Resources</targetPath>
156 <filtering>false</filtering>
157 <directory>Resources</directory>
158 </resource>
159 <resource>
160 <targetPath>WebServerResources</targetPath>
161 <filtering>false</filtering>
162 <directory>WebServerResources</directory>
163 </resource>
164 </resources>
165 <...>
166 </build>
167 <...>
168
169 {{/code}}
170
171 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).
172
173 === Project Dependencies Concepts ===
174
175 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]].
176
177 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.
178
179 {{noformat}}
180
181 <dependencies>
182 <dependency>
183 <artifactId>CustomExtensions</artifactId>
184 <groupId>com.mywostuff.frameworks</groupId>
185 <version>0.0.1-SNAPSHOT</version>
186 <scope>compile</scope>
187 </dependency>
188 <dependency>
189 <groupId>log4j</groupId>
190 <artifactId>log4j</artifactId>
191 <version>1.2.12</version>
192 <scope>compile</scope>
193 </dependency>
194 <dependency>
195 <groupId>junit</groupId>
196 <artifactId>junit</artifactId>
197 <version>4.4</version>
198 <scope>test</scope>
199 </dependency>
200 </dependencies>
201
202 {{/noformat}}
203
204 === Repositories ===
205
206 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]].
207
208 {{noformat}}
209
210 <repositories>
211 <repository>
212 <id>system-repo</id>
213 <name>internal repository</name>
214 <!-- TODO switch over to your intranet.domain -->
215 <url>file://${user.home}/.myarchiva</url>
216 <snapshots>
217 <enabled>true</enabled>
218 <updatePolicy>always</updatePolicy>
219 <checksumPolicy>ignore</checksumPolicy>
220 </snapshots>
221 <releases>
222 <enabled>true</enabled>
223 <updatePolicy>always</updatePolicy>
224 <checksumPolicy>ignore</checksumPolicy>
225 </releases>
226 </repository>
227 <repository>
228 <id>maven2-repository.dev.java.net</id>
229 <name>Java.net Repository for Maven</name>
230 <url>http://download.java.net/maven/2</url>
231 <snapshots>
232 <enabled>true</enabled>
233 <updatePolicy>daily</updatePolicy>
234 </snapshots>
235 <releases>
236 <enabled>true</enabled>
237 <updatePolicy>daily</updatePolicy>
238 </releases>
239 </repository>
240 <repository>
241 <id>webobjects.mdimension.com/releases</id>
242 <name>mdimension maven 2 releases repo</name>
243 <url>http://webobjects.mdimension.com/maven2/releases</url>
244 <snapshots>
245 <enabled>false</enabled>
246 </snapshots>
247 <releases>
248 <enabled>true</enabled>
249 </releases>
250 </repository>
251 <repository>
252 <id>webobjects.mdimension.com/snapshots</id>
253 <name>mdimension maven 2 snapshots repo</name>
254 <url>http://webobjects.mdimension.com/maven2/snapshots</url>
255 <snapshots>
256 <enabled>true</enabled>
257 </snapshots>
258 <releases>
259 <enabled>false</enabled>
260 </releases>
261 </repository>
262 <repository>
263 <id>objectstyle-maven2</id>
264 <name>objectstyle maven2 repo</name>
265 <url>http://objectstyle.org/maven2</url>
266 <snapshots>
267 <enabled>false</enabled>
268 </snapshots>
269 <releases>
270 <enabled>true</enabled>
271 </releases>
272 </repository>
273 </repositories>
274
275 {{/noformat}}
276
277 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]].
278
279 === Packaging Frameworks as Jars ===
280
281 Here's the definition for /frameworks/pom.xml. Note that it depends on the following Info.plist file being located under trunk/frameworks/src/main/resources:
282
283 {{attachments patterns="Info.plist" upload="false"}}{{/attachments}}
284
285 {{code title="/frameworks/pom.xml"}}
286
287 <?xml version="1.0" encoding="UTF-8"?>
288 <project xmlns="http://maven.apache.org/POM/4.0.0"
289 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
290 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
291 http://maven.apache.org/xsd/maven-4.0.0.xsd">
292
293 <modelVersion>4.0.0</modelVersion>
294
295 <!-- parent artifact -->
296 <parent>
297 <artifactId>mywostuff</artifactId>
298 <groupId>com</groupId>
299 <version>1.0-SNAPSHOT</version>
300 </parent>
301
302 <!-- artifact identity -->
303 <artifactId>frameworks</artifactId>
304 <groupId>com.mywostuff</groupId>
305 <packaging>pom</packaging>
306
307 <!-- framework relevant properties -->
308 <properties>
309 <!-- NS related properties fills in Info.plist etc-->
310 <CFBundleDevelopmentRegion>English</CFBundleDevelopmentRegion>
311 <CFBundleGetInfoString></CFBundleGetInfoString>
312 <CFBundlePackageType>FMWK</CFBundlePackageType>
313 <CFBundleIconFile>WOAfile.icns</CFBundleIconFile>
314 <CFBundleInfoDictionaryVersion>6.0</CFBundleInfoDictionaryVersion>
315 <CFBundleVersion>5.3.1</CFBundleVersion>
316 <Has_WOComponents>true</Has_WOComponents>
317 <NSPrincipalClass>${mainclass}</NSPrincipalClass>
318 <NSResourcesBundlePath></NSResourcesBundlePath>
319 </properties>
320
321 <!-- modules -->
322 <modules>
323 <module>CustomExtensions</module>
324 <module>CustomBusinessLogic</module>
325 </modules>
326
327 <!-- specific dependencies (for modules) -->
328 <dependencies>
329 <dependency>
330 <artifactId>ERExtensions</artifactId>
331 <groupId>${wonder.common.groupId}</groupId>
332 </dependency>
333 <dependency>
334 <artifactId>JavaWOExtensions</artifactId>
335 <groupId>${wonder.common.groupId}</groupId>
336 </dependency>
337 <dependency>
338 <artifactId>JavaFoundation</artifactId>
339 <groupId>${webobjects.groupId}</groupId>
340 </dependency>
341 <dependency>
342 <artifactId>JavaJDBCAdaptor</artifactId>
343 <groupId>${webobjects.groupId}</groupId>
344 </dependency>
345 <dependency>
346 <artifactId>JavaWebObjects</artifactId>
347 <groupId>${webobjects.groupId}</groupId>
348 </dependency>
349 <dependency>
350 <artifactId>JavaEOControl</artifactId>
351 <groupId>${webobjects.groupId}</groupId>
352 </dependency>
353 <dependency>
354 <artifactId>JavaEOAccess</artifactId>
355 <groupId>${webobjects.groupId}</groupId>
356 </dependency>
357 <dependency>
358 <artifactId>JavaWebObjects</artifactId>
359 <groupId>${webobjects.groupId}</groupId>
360 </dependency>
361 <dependency>
362 <artifactId>JavaXML</artifactId>
363 <groupId>${webobjects.groupId}</groupId>
364 </dependency>
365 </dependencies>
366
367
368 <!-- build config (for modules) -->
369 <build>
370 <sourceDirectory>src</sourceDirectory>
371 <testSourceDirectory>tests</testSourceDirectory>
372 <resources>
373 <!-- relative dir for Info.plist -->
374 <resource>
375 <targetPath>Resources</targetPath>
376 <filtering>true</filtering>
377 <directory>../src/main/resources</directory>
378 </resource>
379 <resource>
380 <targetPath>Resources</targetPath>
381 <filtering>false</filtering>
382 <directory>Components</directory>
383 </resource>
384 <resource>
385 <targetPath>Resources</targetPath>
386 <filtering>false</filtering>
387 <directory>Resources</directory>
388 </resource>
389 <resource>
390 <targetPath>WebServerResources</targetPath>
391 <filtering>false</filtering>
392 <directory>WebServerResources</directory>
393 </resource>
394 </resources>
395 <plugins>
396 <plugin>
397 <groupId>org.apache.maven.plugins</groupId>
398 <artifactId>maven-compiler-plugin</artifactId>
399 <configuration>
400 <source>${java.target}</source>
401 <target>${java.target}</target>
402 </configuration>
403 </plugin>
404 </plugins>
405 </build>
406 </project>
407
408 {{/code}}
409
410 and CustomExtensions which has no further dependencies
411
412 {{code title="/frameworks/CustomBusinessLogic/pom.xml"}}
413
414 <?xml version="1.0"?>
415 <project>
416 <!-- parent artifact -->
417 <parent>
418 <artifactId>frameworks</artifactId>
419 <groupId>com.mywostuff</groupId>
420 <version>1.0-SNAPSHOT</version>
421 </parent>
422
423 <!-- artifact identity -->
424 <artifactId>CustomBusinessLogic</artifactId>
425 <groupId>com.mywostuff.frameworks</groupId>
426 </project>
427
428 {{/code}}
429
430 and CustomBusinessLogic (which has a further dependency on CustomExtensions)
431
432 {{code title="/frameworks/CustomBusinessLogic/pom.xml"}}
433
434 <?xml version="1.0"?>
435 <project>
436 <!-- parent artifact -->
437 <parent>
438 <artifactId>frameworks</artifactId>
439 <groupId>com.mywostuff</groupId>
440 <version>1.0-SNAPSHOT</version>
441 </parent>
442
443 <!-- artifact identity -->
444 <artifactId>CustomBusinessLogic</artifactId>
445 <groupId>com.mywostuff.frameworks</groupId>
446
447 <!-- specific dependencies -->
448 <dependencies>
449 <dependency>
450 <artifactId>CustomExtensions</artifactId>
451 <groupId>${pom.groupId}</groupId>
452 </dependency>
453 </dependencies>
454 </project>
455
456 {{/code}}
457
458 === Packaging Applications ===
459
460 Here's the definition for /apps/pom.xml which is shared by any sub-modules (i.e., ApplicationA and ApplicationB).
461
462 {{code title="/apps/pom.xml"}}
463
464 <?xml version="1.0" encoding="UTF-8"?>
465 <project xmlns="http://maven.apache.org/POM/4.0.0"
466 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
467 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
468 http://maven.apache.org/xsd/maven-4.0.0.xsd">
469
470 <modelVersion>4.0.0</modelVersion>
471
472 <!-- parent artifact -->
473 <parent>
474 <groupId>com</groupId>
475 <artifactId>mywostuff</artifactId>
476 <version>1.0-SNAPSHOT</version>
477 </parent>
478
479 <!-- artifact identity -->
480 <artifactId>apps</artifactId>
481 <groupId>com.mywostuff</groupId>
482 <packaging>pom</packaging>
483
484 <!-- modules -->
485 <modules>
486 <module>ApplicationA</module>
487 <module>ApplicationB</module>
488 </modules>
489
490 <!-- specific dependencies (for modules) -->
491 <dependencies>
492 <!-- wonder frameworks -->
493 <dependency>
494 <artifactId>ERExtensions</artifactId>
495 <groupId>${wonder.common.groupId}</groupId>
496 </dependency>
497 <dependency>
498 <artifactId>JavaWOExtensions</artifactId>
499 <groupId>${wonder.common.groupId}</groupId>
500 </dependency>
501
502 <!-- project libs -->
503 <dependency>
504 <artifactId>CustomExtensions</artifactId>
505 <groupId>${my.frameworks.groupId}</groupId>
506 </dependency>
507 <dependency>
508 <artifactId>CustomBusinessLogic</artifactId>
509 <groupId>${my.frameworks.groupId}</groupId>
510 </dependency>
511
512 <!-- webobjects dependencies -->
513 <dependency>
514 <artifactId>JavaFoundation</artifactId>
515 <groupId>${webobjects.groupId}</groupId>
516 </dependency>
517 <dependency>
518 <artifactId>JavaJDBCAdaptor</artifactId>
519 <groupId>${webobjects.groupId}</groupId>
520 </dependency>
521 <dependency>
522 <artifactId>JavaWebObjects</artifactId>
523 <groupId>${webobjects.groupId}</groupId>
524 </dependency>
525 <dependency>
526 <artifactId>JavaEOControl</artifactId>
527 <groupId>${webobjects.groupId}</groupId>
528 </dependency>
529 <dependency>
530 <artifactId>JavaEOAccess</artifactId>
531 <groupId>${webobjects.groupId}</groupId>
532 </dependency>
533 <dependency>
534 <artifactId>JavaWebObjects</artifactId>
535 <groupId>${webobjects.groupId}</groupId>
536 </dependency>
537 <dependency>
538 <artifactId>JavaXML</artifactId>
539 <groupId>${webobjects.groupId}</groupId>
540 </dependency>
541 </dependencies>
542
543 <!-- build config (for modules) -->
544 <build>
545 <sourceDirectory>src</sourceDirectory>
546 <testSourceDirectory>tests</testSourceDirectory>
547 <resources>
548 <resource>
549 <targetPath>Resources</targetPath>
550 <filtering>false</filtering>
551 <directory>Components</directory>
552 </resource>
553 <resource>
554 <targetPath>Resources</targetPath>
555 <filtering>false</filtering>
556 <directory>Resources</directory>
557 </resource>
558 <resource>
559 <targetPath>WebServerResources</targetPath>
560 <filtering>false</filtering>
561 <directory>WebServerResources</directory>
562 </resource>
563 </resources>
564 <plugins>
565 <plugin>
566 <artifactId>maven-wolifecycle-plugin</artifactId>
567 <groupId>org.objectstyle.woproject.maven2</groupId>
568 <version>2.0.15</version>
569 <extensions>true</extensions>
570 <configuration>
571 <source>${java.target}</source>
572 <target>${java.target}</target>
573 </configuration>
574 </plugin>
575 <plugin>
576 <groupId>org.apache.maven.plugins</groupId>
577 <artifactId>maven-javadoc-plugin</artifactId>
578 <configuration>
579 <javadocVersion>${java.target}</javadocVersion>
580 <locale>en-AU</locale>
581 <minmemory>128m</minmemory>
582 <maxmemory>512m</maxmemory>
583 </configuration>
584 </plugin>
585 <!--
586 TODO build numbering
587 <plugin>
588 <groupId>org.codehaus.mojo</groupId>
589 <artifactId>maven-buildnumber-plugin</artifactId>
590 <version>0.9.6</version>
591 <executions>
592 <execution>
593 <phase>validate</phase>
594 <goals>
595 <goal>create</goal>
596 </goals>
597 </execution>
598 </executions>
599 <configuration>
600 <doCheck>true</doCheck>
601 <doUpdate>true</doUpdate>
602 </configuration>
603 </plugin>
604 -->
605 </plugins>
606 <pluginManagement>
607 <plugins>
608 <plugin>
609 <groupId>org.apache.maven.plugins</groupId>
610 <artifactId>maven-compiler-plugin</artifactId>
611 <configuration>
612 <source>${java.target}</source>
613 <target>${java.target}</target>
614 </configuration>
615 </plugin>
616 </plugins>
617 </pluginManagement>
618 </build>
619 </project>
620
621 {{/code}}
622
623 and ApplicationA - which has a couple of extra specific dependencies to add to those inherited from its parent.
624
625 {{code title="/apps/ApplicationA/pom.xml"}}
626
627 <?xml version="1.0"?>
628 <project>
629 <modelVersion>4.0.0</modelVersion>
630
631 <!-- parent artifact -->
632 <parent>
633 <artifactId>apps</artifactId>
634 <groupId>com.mywostuff</groupId>
635 <version>1.0-SNAPSHOT</version>
636 <relativePath>../apps</relativePath> <!-- e.g., (optional) if your app is under /trunk -->
637 </parent>
638
639 <!-- artifact identity -->
640 <artifactId>ApplicationA</artifactId>
641 <groupId>com.mywostuff.apps</groupId>
642 <packaging>woapplication</packaging> <!-- woproject specific packaging -->
643
644 <!-- specific properties -->
645 <properties>
646 <!-- general properties -->
647 <mainclass>your.app.Application</mainclass>
648 </properties>
649
650 <!-- specific dependencies -->
651 <dependencies>
652 <!-- wonder frameworks -->
653 <dependency>
654 <artifactId>Ajax</artifactId>
655 <groupId>${wonder.ajax.groupId}</groupId>
656 </dependency>
657 <dependency>
658 <artifactId>ERCaptcha</artifactId>
659 <groupId>${wonder.common.groupId}</groupId>
660 <!-- requires jcaptcha-all below -->
661 </dependency>
662 <dependency>
663 <artifactId>WOOgnl</artifactId>
664 <groupId>${wonder.common.groupId}</groupId>
665 </dependency>
666
667 <!-- general libs -->
668 <dependency>
669 <artifactId>jcaptcha-all</artifactId>
670 <groupId>com.octo.captcha</groupId>
671 </dependency>
672 <dependency>
673 <artifactId>commons-collections</artifactId>
674 <groupId>commons-collections</groupId>
675 </dependency>
676 <dependency>
677 <groupId>ognl</groupId>
678 <artifactId>ognl</artifactId>
679 </dependency>
680 </dependencies>
681 </project>
682
683 {{/code}}
684
685 === Packaging Applications as True WAR ===
686
687 You can find steps to package WO Applications as True WAR [[here>>Packaging WO Applications as true WAR with Maven]].
688
689 more details to come...
690
691 === Project Inheritance ===
692
693 details to come...
694
695 === Eclipse Integration ===
696
697 details to come...
698
699 === Putting It All Together ===
700
701 details to come...