Changes for page Maven Kicking the tyres without changing your project structure
Last modified by Henrique Prange on 2015/09/11 17:57
To version 28.1
edited by Ramsey Gurley
on 2015/09/11 17:57
on 2015/09/11 17:57
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.ramsey - Content
-
... ... @@ -1,29 +1,36 @@ 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"]]. 4 4 5 - It's_really_worthdoingyourhomeworkonmavenin orderto understandit. Theplaceo startis LearningMaven foundat[http://maven.apache.org]. Variousguidesalso foundat [http://maven.apache.org/guides/].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"]]. 6 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 - 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"]]. 11 11 {{/info}} 12 12 13 13 {{tip title="Hang in there"}} 14 - 15 15 This particular guide might look long but some of the xml is duplicated a few times to show differing examples. 16 - 17 17 {{/tip}} 18 18 19 -=== Wh at'stheaim===15 +=== 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.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. 22 22 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 + 23 23 The layout of the frameworks and applications might look like this: 24 24 25 25 {{noformat}} 26 - 27 27 /trunk/ 28 28 /trunk/apps/ 29 29 /trunk/apps/ApplicationA/ ... ... @@ -35,9 +35,9 @@ 35 35 36 36 {{/noformat}} 37 37 38 -Our a imis twofold: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: 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. 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. 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 === ... ... @@ -44,30 +44,30 @@ 44 44 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 -1. pom identification (who am I?) 48 -The base triplet used to identify an artifact (i.e., product) 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) 49 49 50 50 {{noformat}} 51 - 52 52 <artifactId>CustomExtensions</artifactId> 53 53 <groupId>com.mywostuff.frameworks</groupId> 54 54 <version>0.0.1-SNAPSHOT</version> 55 55 56 56 {{/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) 57 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 61 {{noformat}} 70 + <packaging>woapplication</packaging> 62 62 63 - <packaging>woapplication</artifactId> 64 - 65 65 {{/noformat}} 73 +))) 74 +1. ((( 75 +pom parent identification (who do I belong to?) 66 66 67 -1. pom parent identification (who do I belong to?) 68 - 69 69 {{noformat}} 70 - 71 71 <parent> 72 72 <artifactId>frameworks</artifactId> 73 73 <groupId>com.mywostuff</groupId> ... ... @@ -74,11 +74,11 @@ 74 74 </parent> 75 75 76 76 {{/noformat}} 84 +))) 85 +1. ((( 86 +modules (a.k.a kids; who belongs to me?) 77 77 78 -1. modules (a.k.a kids; who belongs to me?) 79 - 80 80 {{noformat}} 81 - 82 82 <modules> 83 83 <module>CustomExtensions</module> 84 84 <module>CustomBusinessLogic</module> ... ... @@ -85,11 +85,11 @@ 85 85 </modules> 86 86 87 87 {{/noformat}} 95 +))) 96 +1. ((( 97 +dependencies (what do I need?) 88 88 89 -1. dependencies (what do I need?) 90 - 91 91 {{noformat}} 92 - 93 93 <dependencies> 94 94 <dependency> 95 95 <groupId>log4j</groupId> ... ... @@ -106,7 +106,7 @@ 106 106 </dependencies> 107 107 108 108 {{/noformat}} 109 - 116 +))) 110 110 1. build sources/resources (what do I have?) 111 111 1. properties and filtering resources (variable definitions) 112 112 1. dependency/plugin management (shared configuration and versioning) ... ... @@ -116,18 +116,15 @@ 116 116 117 117 === Alternate File System Layout Concepts === 118 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. 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. 120 120 121 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 - 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"]]. 125 125 {{/tip}} 126 126 127 -The following roughly resembles the current WebObjects WOLips produced project layout (a.k.a Fluffy Bunny layout). 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). 128 128 129 129 {{noformat}} 130 - 131 131 /MyProject 132 132 /MyProject/Components 133 133 /MyProject/Resources ... ... @@ -137,10 +137,9 @@ 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)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) 141 141 142 -{{code title="pom.xml"}} 143 - 146 +{{code title="pom.xml" 0="xml"}} 144 144 <...> 145 145 <build> 146 146 <sourceDirectory>Sources</sourceDirectory> ... ... @@ -172,12 +172,11 @@ 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]].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"]]. 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.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. 178 178 179 179 {{noformat}} 180 - 181 181 <dependencies> 182 182 <dependency> 183 183 <artifactId>CustomExtensions</artifactId> ... ... @@ -203,16 +203,15 @@ 203 203 204 204 === Project Inheritance === 205 205 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. 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. 207 207 208 208 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. 209 209 210 210 === Repositories === 211 211 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]]. 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. 213 213 214 214 {{noformat}} 215 - 216 216 <repositories> 217 217 <repository> 218 218 <id>system-repo</id> ... ... @@ -280,16 +280,17 @@ 280 280 281 281 {{/noformat}} 282 282 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]].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"]]. 284 284 285 285 === Packaging Frameworks as Jars === 286 286 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: 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): 288 288 289 -{{attachments patterns="Info.plist" upload="false"}}{{/attachments}} 290 290 291 -{{code title="/frameworks/pom.xml"}} 292 292 292 +{{attachments patterns="Info.plist" upload="false"/}} 293 + 294 +{{code title="/frameworks/pom.xml" 0="xml"}} 293 293 <?xml version="1.0" encoding="UTF-8"?> 294 294 <project xmlns="http://maven.apache.org/POM/4.0.0" 295 295 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ... ... @@ -413,10 +413,9 @@ 413 413 414 414 {{/code}} 415 415 416 - andCustomExtensionswhich has no further dependencies418 +Since our CustomExtensions has no further dependencies, its pom.xml merely specifies its parent and its identity. 417 417 418 -{{code title="/frameworks/CustomBusinessLogic/pom.xml"}} 419 - 420 +{{code title="/frameworks/CustomBusinessLogic/pom.xml" 0="xml"}} 420 420 <?xml version="1.0"?> 421 421 <project> 422 422 <!-- parent artifact --> ... ... @@ -433,10 +433,9 @@ 433 433 434 434 {{/code}} 435 435 436 - andCustomBusinessLogic(which has a further dependency on CustomExtensions)437 +CustomBusinessLogic has a further dependency on CustomExtensions, so it specifies its parent, its identity, and the dependency. 437 437 438 -{{code title="/frameworks/CustomBusinessLogic/pom.xml"}} 439 - 439 +{{code title="/frameworks/CustomBusinessLogic/pom.xml" 0="xml"}} 440 440 <?xml version="1.0"?> 441 441 <project> 442 442 <!-- parent artifact --> ... ... @@ -463,10 +463,9 @@ 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). 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. 467 467 468 -{{code title="/apps/pom.xml"}} 469 - 468 +{{code title="/apps/pom.xml" 0="xml"}} 470 470 <?xml version="1.0" encoding="UTF-8"?> 471 471 <project xmlns="http://maven.apache.org/POM/4.0.0" 472 472 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ... ... @@ -626,10 +626,9 @@ 626 626 627 627 {{/code}} 628 628 629 -an dApplicationA-whichhas a couple of extra specific dependencies toaddto those inherited from its parent.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. 630 630 631 -{{code title="/apps/ApplicationA/pom.xml"}} 632 - 630 +{{code title="/apps/ApplicationA/pom.xml" 0="xml"}} 633 633 <?xml version="1.0"?> 634 634 <project> 635 635 <modelVersion>4.0.0</modelVersion> ... ... @@ -690,7 +690,7 @@ 690 690 691 691 === Packaging Applications as True WAR === 692 692 693 -You can find steps to package WO Applications as True WAR [[here>>Packaging WO Applications as true WAR with Maven]]. 691 +You can find steps to package WO Applications as True WAR [[here>>doc:WOL.Packaging WO Applications as true WAR with Maven]]. 694 694 695 695 === Eclipse Integration === 696 696