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 27.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. pierce1 +XWiki.ldeck - Content
-
... ... @@ -1,33 +1,25 @@ 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 - Atthe very least you wanttohave read through,andunderstood,the[[GettingStartedTutorial>>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 -=== Wh y 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 frameworksorlibrarieswillthemselves often depend on thirdpartyframeworkslike 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}} ... ... @@ -43,9 +43,9 @@ 43 43 44 44 {{/noformat}} 45 45 46 - This is a pretty standard way for many WOdevelopers to group theirprojects. Framework projects gointo frameworks,appsinto apps.We can leveragethat standard layout toaccomplish two things:38 +Our aim is twofold: 47 47 48 -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. 49 49 1. Be able to issue a single command that will package each and every framework and application. 50 50 51 51 === Key Concepts === ... ... @@ -53,29 +53,51 @@ 53 53 Typical things that make up a pom are as follows. (Note: only pom identification is mandatory. All the others have defaults.) 54 54 55 55 1. pom identification (who am I?) 56 - The base triplet used to identify an artifact (i.e., something you need to build/package/install) 57 -1. {{noformat}} 48 +The base triplet used to identify an artifact (i.e., product) 49 + 50 +{{noformat}} 51 + 58 58 <artifactId>CustomExtensions</artifactId> 59 59 <groupId>com.mywostuff.frameworks</groupId> 60 60 <version>0.0.1-SNAPSHOT</version> 61 -{{/noformat}}pom packaging (i.e., what are we building?) 62 - 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) 63 -1. {{noformat}} 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 + 64 64 <packaging>woapplication</artifactId> 65 -{{/noformat}}pom parent identification (who do I belong to?) 66 -1. {{noformat}} 64 + 65 +{{/noformat}} 66 + 67 +1. pom parent identification (who do I belong to?) 68 + 69 +{{noformat}} 70 + 67 67 <parent> 68 68 <artifactId>frameworks</artifactId> 69 69 <groupId>com.mywostuff</groupId> 70 70 </parent> 71 -{{/noformat}}modules (a.k.a kids; who belongs to me?) 72 -1. {{noformat}} 75 + 76 +{{/noformat}} 77 + 78 +1. modules (a.k.a kids; who belongs to me?) 79 + 80 +{{noformat}} 81 + 73 73 <modules> 74 74 <module>CustomExtensions</module> 75 75 <module>CustomBusinessLogic</module> 76 76 </modules> 77 -{{/noformat}}dependencies (what do I need?) 78 -1. {{noformat}} 86 + 87 +{{/noformat}} 88 + 89 +1. dependencies (what do I need?) 90 + 91 +{{noformat}} 92 + 79 79 <dependencies> 80 80 <dependency> 81 81 <groupId>log4j</groupId> ... ... @@ -90,7 +90,10 @@ 90 90 <scope>test</scope> 91 91 </dependency> 92 92 </dependencies> 93 -{{/noformat}}build sources/resources (what do I have?) 107 + 108 +{{/noformat}} 109 + 110 +1. build sources/resources (what do I have?) 94 94 1. properties and filtering resources (variable definitions) 95 95 1. dependency/plugin management (shared configuration and versioning) 96 96 1. repositories (where to find dependencies and plugins) ... ... @@ -99,13 +99,15 @@ 99 99 100 100 === Alternate File System Layout Concepts === 101 101 102 -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. 103 103 104 104 {{tip title="Mavan Model Reference Doco"}} 105 -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 + 106 106 {{/tip}} 107 107 108 - 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). 109 109 110 110 {{noformat}} 111 111 ... ... @@ -118,9 +118,9 @@ 118 118 119 119 {{/noformat}} 120 120 121 -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.xmland 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) 122 122 123 -{{code title="pom.xml" 0="xml"}}142 +{{code title="pom.xml"}} 124 124 125 125 <...> 126 126 <build> ... ... @@ -153,9 +153,9 @@ 153 153 154 154 === Project Dependencies Concepts === 155 155 156 -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]]. 157 157 158 -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. 159 159 160 160 {{noformat}} 161 161 ... ... @@ -184,13 +184,13 @@ 184 184 185 185 === Project Inheritance === 186 186 187 -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. 188 188 189 189 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. 190 190 191 191 === Repositories === 192 192 193 -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]]. 194 194 195 195 {{noformat}} 196 196 ... ... @@ -261,15 +261,15 @@ 261 261 262 262 {{/noformat}} 263 263 264 -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]]. 265 265 266 266 === Packaging Frameworks as Jars === 267 267 268 -Here's the definition for /frameworks/pom.xml , definitions here will be shared by all of the individual framework pom.xmlfiles.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: 269 269 270 -{{attachments patterns="Info.plist" upload="false"/}} 289 +{{attachments patterns="Info.plist" upload="false"}}{{/attachments}} 271 271 272 -{{code title="/frameworks/pom.xml" 0="xml"}}291 +{{code title="/frameworks/pom.xml"}} 273 273 274 274 <?xml version="1.0" encoding="UTF-8"?> 275 275 <project xmlns="http://maven.apache.org/POM/4.0.0" ... ... @@ -394,9 +394,9 @@ 394 394 395 395 {{/code}} 396 396 397 - SinceourCustomExtensions has no further dependencies, its pom.xml merely specifies its parent and its identity.416 +and CustomExtensions which has no further dependencies 398 398 399 -{{code title="/frameworks/CustomBusinessLogic/pom.xml" 0="xml"}}418 +{{code title="/frameworks/CustomBusinessLogic/pom.xml"}} 400 400 401 401 <?xml version="1.0"?> 402 402 <project> ... ... @@ -414,9 +414,9 @@ 414 414 415 415 {{/code}} 416 416 417 -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) 418 418 419 -{{code title="/frameworks/CustomBusinessLogic/pom.xml" 0="xml"}}438 +{{code title="/frameworks/CustomBusinessLogic/pom.xml"}} 420 420 421 421 <?xml version="1.0"?> 422 422 <project> ... ... @@ -444,9 +444,9 @@ 444 444 445 445 === Packaging Applications === 446 446 447 -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). 448 448 449 -{{code title="/apps/pom.xml" 0="xml"}}468 +{{code title="/apps/pom.xml"}} 450 450 451 451 <?xml version="1.0" encoding="UTF-8"?> 452 452 <project xmlns="http://maven.apache.org/POM/4.0.0" ... ... @@ -607,9 +607,9 @@ 607 607 608 608 {{/code}} 609 609 610 - With most stuff specified in the parentpom,ApplicationAneedsonly to specifyits parent, itsidenity,andadd acouple 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. 611 611 612 -{{code title="/apps/ApplicationA/pom.xml" 0="xml"}}631 +{{code title="/apps/ApplicationA/pom.xml"}} 613 613 614 614 <?xml version="1.0"?> 615 615 <project> ... ... @@ -671,7 +671,7 @@ 671 671 672 672 === Packaging Applications as True WAR === 673 673 674 -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]]. 675 675 676 676 === Eclipse Integration === 677 677