Version 18.1 by Henrique Prange on 2008/06/15 19:35

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
51 {{/noformat}}
52
53 1. pom packaging (i.e., what are we building?)
54 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)
55
56 {{noformat}}
57
58 <packaging>woapplication</artifactId>
59
60
61 {{/noformat}}
62
63 1. pom parent identification (who do I belong to?)
64
65 {{noformat}}
66
67 <parent>
68 <artifactId>frameworks</artifactId>
69 <groupId>com.mywostuff</groupId>
70 </parent>
71
72
73 {{/noformat}}
74
75 1. modules (a.k.a kids; who belongs to me?)
76
77 {{noformat}}
78
79 <modules>
80 <module>CustomExtensions</module>
81 <module>CustomBusinessLogic</module>
82 </modules>
83
84
85 {{/noformat}}
86
87 1. dependencies (what do I need?)
88
89 {{noformat}}
90
91 <dependencies>
92 <dependency>
93 <groupId>log4j</groupId>
94 <artifactId>log4j</artifactId>
95 <version>1.2.12</version>
96 <scope>compile</scope>
97 </dependency>
98 <dependency>
99 <groupId>junit</groupId>
100 <artifactId>junit</artifactId>
101 <version>4.4</version>
102 <scope>test</scope>
103 </dependency>
104 </dependencies>
105
106
107 {{/noformat}}
108
109 1. build sources/resources (what do I have?)
110 1. properties and filtering resources (variable definitions)
111 1. dependency/plugin management (shared configuration and versioning)
112 1. repositories (where to find dependencies and plugins)
113
114 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.
115
116 === Alternate File System Layout Concepts ===
117
118 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.
119
120 {{tip title="Mavan Model Reference Doco"}}
121
122 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].
123
124 {{/tip}}
125
126 The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout).
127
128 {{noformat}}
129
130 /MyProject
131 /MyProject/Components
132 /MyProject/Resources
133 /MyProject/Sources
134 /MyProject/Tests
135 /MyProject/WebServerResources
136
137 {{/noformat}}
138
139 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)
140
141 {{code title="pom.xml"}}
142
143 <...>
144 <build>
145 <sourceDirectory>Sources</sourceDirectory>
146 <testSourceDirectory>Tests</testSourceDirectory>
147 <resources>
148 <resource>
149 <targetPath>Resources</targetPath>
150 <filtering>false</filtering>
151 <directory>Components</directory>
152 </resource>
153 <resource>
154 <targetPath>Resources</targetPath>
155 <filtering>false</filtering>
156 <directory>Resources</directory>
157 </resource>
158 <resource>
159 <targetPath>WebServerResources</targetPath>
160 <filtering>false</filtering>
161 <directory>WebServerResources</directory>
162 </resource>
163 </resources>
164 <...>
165 </build>
166 <...>
167
168 {{/code}}
169
170 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).
171
172 === Project Dependencies Concepts ===
173
174 Most projects, of course, have dependencies on other libraries or frameworks.
175
176 === Project Dependencies Prerequisites ===
177
178 details to come...
179
180 === Packaging Frameworks as Jars ===
181
182 details to come...
183
184 === Packaging Applications ===
185
186 details to come...
187
188 === Packaging Applications as True WAR ===
189
190 You can find steps to package WO Applications as True WAR [[here>>Packaging WO Applications as true WAR with Maven]].
191
192 more details to come...
193
194 === Project Inheritance ===
195
196 details to come...
197
198 === Eclipse Integration ===
199
200 details to come...
201
202 === Putting It All Together ===
203
204 details to come...