Changes for page Maven Kicking the tyres without changing your project structure
Last modified by Henrique Prange on 2015/09/11 17:57
From version 20.1
edited by Lachlan Deck
on 2008/07/02 23:41
on 2008/07/02 23:41
Change comment:
Adding example for building WOApplications
To version 10.1
edited by pierce
on 2008/07/03 14:25
on 2008/07/03 14:25
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. ldeck1 +XWiki.pierce - Content
-
... ... @@ -16,10 +16,22 @@ 16 16 17 17 {{/tip}} 18 18 19 -=== Wh at'stheaim===19 +=== Why Maven === 20 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. Solet'sassumewe have multipleframeworksandapplications in our build.Each ofthesehassomecommonground, such as their dependenciesoncertainWebObjectsframeworks,or the filelayout,and ofcourse theyeach may have something distinctiveaboutthem.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. In addition, those frameworks or libraries will themselves often depend on third party frameworks like apache commons, log4j, or WebObjects. 22 22 23 +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. 24 + 25 +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. 26 + 27 +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. 28 + 29 +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. 30 + 31 +=== A sample build === 32 + 33 +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. 34 + 23 23 The layout of the frameworks and applications might look like this: 24 24 25 25 {{noformat}} ... ... @@ -35,9 +35,9 @@ 35 35 36 36 {{/noformat}} 37 37 38 -Our a imis twofold:50 +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: 39 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. 52 +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. 41 41 1. Be able to issue a single command that will package each and every framework and application. 42 42 43 43 === Key Concepts === ... ... @@ -45,7 +45,7 @@ 45 45 Typical things that make up a pom are as follows. (Note: only pom identification is mandatory. All the others have defaults.) 46 46 47 47 1. pom identification (who am I?) 48 -The base triplet used to identify an artifact (i.e., product)60 +The base triplet used to identify an artifact (i.e., something you need to build/package/install) 49 49 50 50 {{noformat}} 51 51 ... ... @@ -124,7 +124,7 @@ 124 124 125 125 {{/tip}} 126 126 127 -The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout). 139 +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). 128 128 129 129 {{noformat}} 130 130 ... ... @@ -137,7 +137,7 @@ 137 137 138 138 {{/noformat}} 139 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) 152 +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//>>http://maven.apache.org/ref/2.0.9/maven-model/maven.html#class_resource]] for a definition of targetPath) 141 141 142 142 {{code title="pom.xml"}} 143 143 ... ... @@ -172,9 +172,9 @@ 172 172 173 173 === Project Dependencies Concepts === 174 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]]. 187 +Most projects, of course, have dependencies on other libraries or frameworks. See the [[WOL: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 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. 189 +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//>>http://maven.apache.org/ref/2.0.9/maven-model/maven.html#class_dependency]] for specific definitions. 178 178 179 179 {{noformat}} 180 180 ... ... @@ -201,9 +201,15 @@ 201 201 202 202 {{/noformat}} 203 203 216 +=== Project Inheritance === 217 + 218 +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. 219 + 220 +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. 221 + 204 204 === Repositories === 205 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]]. 224 +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]]. 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. 207 207 208 208 {{noformat}} 209 209 ... ... @@ -274,11 +274,11 @@ 274 274 275 275 {{/noformat}} 276 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]].295 +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]]. 278 278 279 279 === Packaging Frameworks as Jars === 280 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: 299 +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): 282 282 283 283 {{attachments patterns="Info.plist" upload="false"}}{{/attachments}} 284 284 ... ... @@ -407,7 +407,7 @@ 407 407 408 408 {{/code}} 409 409 410 - andCustomExtensionswhich has no further dependencies428 +Since our CustomExtensions has no further dependencies, its pom.xml merely specifies its parent and its identity. 411 411 412 412 {{code title="/frameworks/CustomBusinessLogic/pom.xml"}} 413 413 ... ... @@ -427,7 +427,7 @@ 427 427 428 428 {{/code}} 429 429 430 - andCustomBusinessLogic(which has a further dependency on CustomExtensions)448 +CustomBusinessLogic has a further dependency on CustomExtensions, so it specifies its parent, its identity, and the dependency. 431 431 432 432 {{code title="/frameworks/CustomBusinessLogic/pom.xml"}} 433 433 ... ... @@ -457,7 +457,7 @@ 457 457 458 458 === Packaging Applications === 459 459 460 -Here's the definition for /apps/pom.xml which is shared by any sub-modules (i.e., ApplicationA and ApplicationB). 478 +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. 461 461 462 462 {{code title="/apps/pom.xml"}} 463 463 ... ... @@ -466,7 +466,7 @@ 466 466 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 467 467 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 468 468 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 469 - 487 + 470 470 <modelVersion>4.0.0</modelVersion> 471 471 472 472 <!-- parent artifact --> ... ... @@ -498,7 +498,7 @@ 498 498 <artifactId>JavaWOExtensions</artifactId> 499 499 <groupId>${wonder.common.groupId}</groupId> 500 500 </dependency> 501 - 519 + 502 502 <!-- project libs --> 503 503 <dependency> 504 504 <artifactId>CustomExtensions</artifactId> ... ... @@ -508,7 +508,7 @@ 508 508 <artifactId>CustomBusinessLogic</artifactId> 509 509 <groupId>${my.frameworks.groupId}</groupId> 510 510 </dependency> 511 - 529 + 512 512 <!-- webobjects dependencies --> 513 513 <dependency> 514 514 <artifactId>JavaFoundation</artifactId> ... ... @@ -539,7 +539,7 @@ 539 539 <groupId>${webobjects.groupId}</groupId> 540 540 </dependency> 541 541 </dependencies> 542 - 560 + 543 543 <!-- build config (for modules) --> 544 544 <build> 545 545 <sourceDirectory>src</sourceDirectory> ... ... @@ -620,7 +620,7 @@ 620 620 621 621 {{/code}} 622 622 623 -an dApplicationA-whichhas a couple of extra specific dependencies toaddto those inherited from its parent.641 +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. 624 624 625 625 {{code title="/apps/ApplicationA/pom.xml"}} 626 626 ... ... @@ -663,7 +663,7 @@ 663 663 <artifactId>WOOgnl</artifactId> 664 664 <groupId>${wonder.common.groupId}</groupId> 665 665 </dependency> 666 - 684 + 667 667 <!-- general libs --> 668 668 <dependency> 669 669 <artifactId>jcaptcha-all</artifactId> ... ... @@ -684,14 +684,8 @@ 684 684 685 685 === Packaging Applications as True WAR === 686 686 687 -You can find steps to package WO Applications as True WAR [[here>>Packaging WO Applications as true WAR with Maven]]. 705 +You can find steps to package WO Applications as True WAR [[here>>WOL:Packaging WO Applications as true WAR with Maven]]. 688 688 689 -more details to come... 690 - 691 -=== Project Inheritance === 692 - 693 -details to come... 694 - 695 695 === Eclipse Integration === 696 696 697 697 details to come...