Last modified by Henrique Prange on 2015/09/11 17:57

From version 28.1
edited by Ramsey Gurley
on 2015/09/11 17:57
Change comment: There is no comment for this version
To version 23.1
edited by Lachlan Deck
on 2008/07/03 00:05
Change comment: Adding basic info and links for further info on project inheritance

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.ramsey
1 +XWiki.ldeck
Content
... ... @@ -1,36 +1,29 @@
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 2  
3 3  {{info title="Recommended Homework (or pre-requisites)"}}
4 -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>>url:http://maven.apache.org||shape="rect"]]. Various guides are also found at [[http:~~/~~/maven.apache.org/guides/>>url:http://maven.apache.org/guides/||shape="rect"]].
5 5  
6 -At the very least you want to have read through, and understood, the [[Getting Started Tutorial>>url:http://maven.apache.org/guides/getting-started/index.html||shape="rect"]].
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/].
7 7  
8 -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>>url:http://maven.apache.org/users/getting-help.html||shape="rect"]].
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 +
9 9  {{/info}}
10 10  
11 11  {{tip title="Hang in there"}}
14 +
12 12  This particular guide might look long but some of the xml is duplicated a few times to show differing examples.
16 +
13 13  {{/tip}}
14 14  
15 -=== Why Maven ===
19 +=== What's the aim ===
16 16  
17 -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. In addition, those frameworks or libraries will themselves often depend on third party frameworks like apache commons, log4j, or WebObjects.
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.
18 18  
19 -It can be extraordinarily tedious to manage downloading, installing, compiling, and packaging these dependencies. Just finding a particular version of commons-logging-1.1.jar can take 20 minutes. Then everyone in your workgroup has to agree where to put it, and copy it over. If you decide to update to 1.1.1, you have to talk to everyone in your workgroup again, remember to put it into production when you deploy, etc.
20 -
21 -This is not a new problem in computer science. There are other tools that attempt to solve this problem, maven just takes it beyond just the build stage into nightly builds, running tests, packaging, deploying, etc.
22 -
23 -So in essence, the goal of maven is to automate even more of the whole build/test/install process then is currently done, even to the point of downloading software needed as part of the build. In addition, maven emphasizes //standards// over //configuration//. In WebObjects terms, that's a fancy way of saying that if you put your .wo files in Components, maven will know they need to go into the Resources folder in the .woa.
24 -
25 -So while you still have to provide maven with information on the dependencies, if you use the standard locations for things, you won't have to specify much else.
26 -
27 -=== A sample build ===
28 -
29 -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.
30 -
31 31  The layout of the frameworks and applications might look like this:
32 32  
33 33  {{noformat}}
26 +
34 34  /trunk/
35 35  /trunk/apps/
36 36  /trunk/apps/ApplicationA/
... ... @@ -42,9 +42,9 @@
42 42  
43 43  {{/noformat}}
44 44  
45 -This is a pretty standard way for many WO developers to group their projects. Framework projects go into frameworks, apps into apps. We can leverage that standard layout to accomplish two things:
38 +Our aim is twofold:
46 46  
47 -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. This makes the child pom.xml files simpler.
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.
48 48  1. Be able to issue a single command that will package each and every framework and application.
49 49  
50 50  === Key Concepts ===
... ... @@ -51,30 +51,30 @@
51 51  
52 52  Typical things that make up a pom are as follows. (Note: only pom identification is mandatory. All the others have defaults.)
53 53  
54 -1. (((
55 -pom identification (who am I?)
56 - The base triplet used to identify an artifact (i.e., something you need to build/package/install)
47 +1. pom identification (who am I?)
48 +The base triplet used to identify an artifact (i.e., product)
57 57  
58 58  {{noformat}}
51 +
59 59   <artifactId>CustomExtensions</artifactId>
60 60   <groupId>com.mywostuff.frameworks</groupId>
61 61   <version>0.0.1-SNAPSHOT</version>
62 62  
63 63  {{/noformat}}
64 -)))
65 -1. (((
66 -pom packaging (i.e., what are we building?)
67 - 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)
68 68  
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 +
69 69  {{noformat}}
70 - <packaging>woapplication</packaging>
71 71  
63 + <packaging>woapplication</artifactId>
64 +
72 72  {{/noformat}}
73 -)))
74 -1. (((
75 -pom parent identification (who do I belong to?)
76 76  
67 +1. pom parent identification (who do I belong to?)
68 +
77 77  {{noformat}}
70 +
78 78   <parent>
79 79   <artifactId>frameworks</artifactId>
80 80   <groupId>com.mywostuff</groupId>
... ... @@ -81,11 +81,11 @@
81 81   </parent>
82 82  
83 83  {{/noformat}}
84 -)))
85 -1. (((
86 -modules (a.k.a kids; who belongs to me?)
87 87  
78 +1. modules (a.k.a kids; who belongs to me?)
79 +
88 88  {{noformat}}
81 +
89 89   <modules>
90 90   <module>CustomExtensions</module>
91 91   <module>CustomBusinessLogic</module>
... ... @@ -92,11 +92,11 @@
92 92   </modules>
93 93  
94 94  {{/noformat}}
95 -)))
96 -1. (((
97 -dependencies (what do I need?)
98 98  
89 +1. dependencies (what do I need?)
90 +
99 99  {{noformat}}
92 +
100 100   <dependencies>
101 101   <dependency>
102 102   <groupId>log4j</groupId>
... ... @@ -113,7 +113,7 @@
113 113   </dependencies>
114 114  
115 115  {{/noformat}}
116 -)))
109 +
117 117  1. build sources/resources (what do I have?)
118 118  1. properties and filtering resources (variable definitions)
119 119  1. dependency/plugin management (shared configuration and versioning)
... ... @@ -123,15 +123,18 @@
123 123  
124 124  === Alternate File System Layout Concepts ===
125 125  
126 -As you would (i.e., should) have read by now, Maven has what it calls //standards//. One such standard is the [[standard directory layout>>url:http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html_standard||shape="rect"]]. 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.
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.
127 127  
128 128  {{tip title="Mavan Model Reference Doco"}}
129 -To see what built-in options are available for maven see [[Maven Model>>url:http://maven.apache.org/ref/2.0.9/maven-model/maven.html||shape="rect"]].
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 +
130 130  {{/tip}}
131 131  
132 -In this case though, we're just trying to "kick the tyres", so we don't want to have to move our files around. The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout).
127 +The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout).
133 133  
134 134  {{noformat}}
130 +
135 135  /MyProject
136 136  /MyProject/Components
137 137  /MyProject/Resources
... ... @@ -141,9 +141,10 @@
141 141  
142 142  {{/noformat}}
143 143  
144 -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, we can put this in /trunk/pom.xml and then all the child pom.xml files will know we're using Fluffy Bunny Layout. Notice we've also defined the target path for each resource. (See the [[WOL:Maven Model#class_resource>>url:http://maven.apache.org/ref/2.0.9/maven-model/maven.html#class_resource||shape="rect"]] for a definition of targetPath)
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)
145 145  
146 -{{code title="pom.xml" 0="xml"}}
142 +{{code title="pom.xml"}}
143 +
147 147  <...>
148 148   <build>
149 149   <sourceDirectory>Sources</sourceDirectory>
... ... @@ -175,11 +175,12 @@
175 175  
176 176  === Project Dependencies Concepts ===
177 177  
178 -Most projects, of course, have dependencies on other libraries or frameworks. See the [[WOL:Maven Getting Started#How_do_I_use_external_dependencies>>url:http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_external_dependencies||shape="rect"]].
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]].
179 179  
180 -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 [[WOL:Maven Model#class_dependency>>url:http://maven.apache.org/ref/2.0.9/maven-model/maven.html#class_dependency||shape="rect"]] for specific definitions.
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.
181 181  
182 182  {{noformat}}
180 +
183 183   <dependencies>
184 184   <dependency>
185 185   <artifactId>CustomExtensions</artifactId>
... ... @@ -205,15 +205,16 @@
205 205  
206 206  === Project Inheritance ===
207 207  
208 -It naturally gets a bit boring having to define the same things over and over again. So, you can utilise a parent pom file specifying its packaging as 'pom'. Dependencies, plugins and executions, resources specifications and so forth can be defined once and shared by any sub-modules. See [[http:~~/~~/maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance>>url:http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance||shape="rect"]] and [[Java World's The Maven 2 POM demystified>>url:http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html||shape="rect"]] for further information and examples.
206 +It naturally gets a bit boring having to define the same things over and over again. So, you can utilise a parent pom file specifying its packaging as 'pom'. Dependencies, plugins and executions, resources specifications and so forth can be defined once and shared by any sub-modules. See [[http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance]] and [[Java World's The Maven 2 POM demystified>>http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html]] for further information and examples.
209 209  
210 210  For our example we'll have trunk/pom.xml which will define everything common to any and all modules in the hierarchy. Likewise, trunk/frameworks/pom.xml and trunk/apps/pom.xml will define everything common to frameworks and applications respecively.
211 211  
212 212  === Repositories ===
213 213  
214 -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>>url:http://maven.apache.org/guides/introduction/introduction-to-repositories.html||shape="rect"]]. Repositories are what lets you specify, "my app needs commons-logging-1.1.1" and maven can then pull it into the build as needed. Here we're adding some additional repositories to the defaults. You might want to setup one for your workgroup, and then there are some useful WO-related ones as well. We can include this in the master trunk/pom.xml file, then all the children can use it.
212 +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]].
215 215  
216 216  {{noformat}}
215 +
217 217  <repositories>
218 218   <repository>
219 219   <id>system-repo</id>
... ... @@ -281,17 +281,16 @@
281 281  
282 282  {{/noformat}}
283 283  
284 -Note: A remote repository is not guaranteed to keep older versions of libraries, for example, indefinitely. This is why 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>>url:http://www.theserverside.com/tt/articles/article.tss?l=SettingUpMavenRepository||shape="rect"]].
283 +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]].
285 285  
286 286  === Packaging Frameworks as Jars ===
287 287  
288 -Here's the definition for /frameworks/pom.xml, definitions here will be shared by all of the individual framework pom.xml files. Note that it depends on the following Info.plist file being located under trunk/frameworks/src/main/resources (maven builds can use files stored in common off of a shared structure):
287 +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:
289 289  
289 +{{attachments patterns="Info.plist" upload="false"}}{{/attachments}}
290 290  
291 +{{code title="/frameworks/pom.xml"}}
291 291  
292 -{{attachments patterns="Info.plist" upload="false"/}}
293 -
294 -{{code title="/frameworks/pom.xml" 0="xml"}}
295 295  <?xml version="1.0" encoding="UTF-8"?>
296 296  <project xmlns="http://maven.apache.org/POM/4.0.0"
297 297   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
... ... @@ -415,9 +415,10 @@
415 415  
416 416  {{/code}}
417 417  
418 -Since our CustomExtensions has no further dependencies, its pom.xml merely specifies its parent and its identity.
416 +and CustomExtensions which has no further dependencies
419 419  
420 -{{code title="/frameworks/CustomBusinessLogic/pom.xml" 0="xml"}}
418 +{{code title="/frameworks/CustomBusinessLogic/pom.xml"}}
419 +
421 421  <?xml version="1.0"?>
422 422  <project>
423 423   <!-- parent artifact -->
... ... @@ -434,9 +434,10 @@
434 434  
435 435  {{/code}}
436 436  
437 -CustomBusinessLogic has a further dependency on CustomExtensions, so it specifies its parent, its identity, and the dependency.
436 +and CustomBusinessLogic (which has a further dependency on CustomExtensions)
438 438  
439 -{{code title="/frameworks/CustomBusinessLogic/pom.xml" 0="xml"}}
438 +{{code title="/frameworks/CustomBusinessLogic/pom.xml"}}
439 +
440 440  <?xml version="1.0"?>
441 441  <project>
442 442   <!-- parent artifact -->
... ... @@ -463,9 +463,10 @@
463 463  
464 464  === Packaging Applications ===
465 465  
466 -Here's the definition for /apps/pom.xml which is shared by any sub-modules (i.e., ApplicationA and ApplicationB). Both apps need certain WebObjects frameworks, so we specify those only once for both, here in the parent pom. We also specify Fluffy Bunny Layout, and some maven plugins we want to use. Again, this is for both applications.
466 +Here's the definition for /apps/pom.xml which is shared by any sub-modules (i.e., ApplicationA and ApplicationB).
467 467  
468 -{{code title="/apps/pom.xml" 0="xml"}}
468 +{{code title="/apps/pom.xml"}}
469 +
469 469  <?xml version="1.0" encoding="UTF-8"?>
470 470  <project xmlns="http://maven.apache.org/POM/4.0.0"
471 471   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
... ... @@ -625,9 +625,10 @@
625 625  
626 626  {{/code}}
627 627  
628 -With most stuff specified in the parent pom, ApplicationA needs only to specify its parent, its idenity, and add a couple of extra specific dependencies to those inherited from its parent.
629 +and ApplicationA - which has a couple of extra specific dependencies to add to those inherited from its parent.
629 629  
630 -{{code title="/apps/ApplicationA/pom.xml" 0="xml"}}
631 +{{code title="/apps/ApplicationA/pom.xml"}}
632 +
631 631  <?xml version="1.0"?>
632 632  <project>
633 633   <modelVersion>4.0.0</modelVersion>
... ... @@ -688,7 +688,7 @@
688 688  
689 689  === Packaging Applications as True WAR ===
690 690  
691 -You can find steps to package WO Applications as True WAR [[here>>doc:WOL.Packaging WO Applications as true WAR with Maven]].
693 +You can find steps to package WO Applications as True WAR [[here>>Packaging WO Applications as true WAR with Maven]].
692 692  
693 693  === Eclipse Integration ===
694 694