Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Sunday, November 30, 2008
Saturday, November 29, 2008
Maven Basics
This post is based on this serverside article.
The basic concept of Maven is a project. A project can create only one artifact. E.g. a web project can create a war file as an artifact. To work around this restriction of one artifact per project, a project can have sub-projects. Each of the sub-projects can have a artificat by themselves. The project's responsibility now is to take the sub-project's artifacts and make one artifact.
A project is defined as any directory with a project.xml in it. If sub-directories of a project directory have project.xml then they are project directories too.
All project artifacts (artifacts resulting from projects) are stored in repositories. There are remote and local repositories. Local repository is created in ./maven/repository. In windows its "c:/Documents and Settings/. In maven dependencies are expressed between artifacts. Like to create the artificat my_application.war, there is a dependency on version 1.0.2 of commons-logging. This dependency specification is laid out in project.xml. When maven is executed, it reads the project.xml, finds that you depend on commons-logging, picks up the specified version of commons-logging from the remote repository and dump it into the local repository and the version in the local repository is used to build your project's artifact (war in this case).
The structure of repository on a windows box:
//jars/.
c:/Documents and Settings/babu.subburathinam/maven/repository/commons-loggging/jars/commons-logging-1.0.7.jar
Instead of each project having a copy of its dependencies, all libraries are lodged in a repository and all projects share the libraries available in the repository. Each project will inturn publish its artifact on to the repository. This process of a project publishing its artifact is called "install"ing in maven lingo. This process of each project publishing its (snapshot and release) artifacts to a central repository helps in continuous integration. This is how: Daemon processes running in build servers can build each project with its updated dependencies several times a day, deploy and test the built artifacts. Thus, integration issues if any will surface much before the release date of a specific project.
Inputs to maven:
One of the input files to maven is Project Object Model (POM) file. This file describes the project to maven. This file has the following structure:
01
02
033
04Sample-Maven-Project
05sample-project
061.1
07Sample Maven Project
08
09
10
11
12
13
14
15
16
17
Line 2 - Root element of XML
Line 3 - This tag is unused but needed.
Line 4 - A directory with this name is created in Maven repository to hold the artifacts of projects sharing the group id.
Line 5,6 - The id and version is used to create the artifact name as-.jar
Line 7 - Name of the project
The project Management section has project information such as the organization, its web site, location of SCM (Software configuration management), deployment and issue tracking sites, developer lists, mailing lists, etc...Most of this section is optional. The contents of project.xml can be extended. Most of the content is defined at the enterprise level and each project can override what is appropriate to it.
An example of the project management section:
01
02Foobar Travels
03http://www.foobar.com
04http://www.foobar.com/logo.jpg
05
06
072003
08foobar.blah.*
09http://www.foobar.com/project-logo.jpg |
10Project description goes here
11Short Description
12http://www.foobar.com
13http://jira.foobar.com
14http://staging.foobar.com
15/etc/staging
16/etc/builds
17
18
19cvs:pserver:anon@foobar.com:/foo
20http://scm.foobar.com
21
22
23
24
25Dev List
26subscribe-dev@foobar.com
27unsubscribe-dev@foobar.com
28
29 ...
30 ...
31
32
33
34
35Srikanth Shenoy
36shenoy
37srikanth@srikanth.org
38
39 ...
40 ...
41
* Lines 01-05 - Organization details
* Line 08 - Top level package for the project
* Line 09 - Project Logo
* Line 12 - Project web site
* Line 14 - The site where the project is hosted
* Line 15 - Physical location of project deployment
* Line 16 - Physical location where the project distributions are available
* Lines 18-21 - SCM to access the project source
* Lines 23-31 - Mailing list for the project
* Lines 33-41 - Developers in the project
General structure of a maven project:
Maven Project Root
- maven.xml // Project definition file
- src // source directory
-- conf // Configuration within source
---xyz.properties // config gile
--java // java source
---com
----access
-----dev
------Hello.java
- test // test directory
-- conf // test configuration
---abc.properties // test config file
--java // java test files
---com
----access
-----dev
------TestHello.java
Project dependency section
In this section the project indicates all the dependecies that it has on artifacts of other projects. An example:
01
02
03BeanUtils
04commons-beanutils
051.5
06
commons-logging
commons-logging
1.0.3
castor
castor
0.9.4.3
Line 1 - Starts the dependencies
Line 3 - The artifact that this project depends on is at the directory named "BeanUtils" in the repository
Line 4,5 - The artifact name is "commons-beanutils-1.5.jar" (using-.jar)
Project build section
This section indicates the location of source, test and resource files. This is defined at the org. level or main project level for sub-projects to follow. If this section is not specified, no build ever gets done. Once build is over, all unit tests specified in the unit test section are executed. The contents of this section should match the actual layout of the code in the filesystem.
01
02srikanth@srikanth.org
03${basedir}/src/java
04${basedir}/test/java
05
06
07**/*Test.java
08
09
10
11
12
13${basedir}/src/conf
14
15*.properties
16
17
18
19
* Line 02 - Email address to send notification about the build status
* Line 03 - Folder containing the source files for the project. The source can be java, jsp and so on.
* Line 04 - Directory containing the unit test files for the project.
* Lines 05-09 - The test file name pattern to run after the build is completed
* Lines 11-19 - Resources to be copied in case a jar is created.
Project reports sections
Once build is done, reports and documentation about the build are generated.
e.g.
maven-changes-plugin
maven-jdepend-plugin
maven-checkstyle-plugin
maven-pmd-plugin
maven-junit-report-plugin
maven-clover-plugin
maven-changelog-plugin
maven-file-activity-plugin
maven-developer-activity-plugin
maven-file-activity-plugin
maven-license-plugin
maven-linkcheck-plugin
maven-jxr-plugin
The basic concept of Maven is a project. A project can create only one artifact. E.g. a web project can create a war file as an artifact. To work around this restriction of one artifact per project, a project can have sub-projects. Each of the sub-projects can have a artificat by themselves. The project's responsibility now is to take the sub-project's artifacts and make one artifact.
A project is defined as any directory with a project.xml in it. If sub-directories of a project directory have project.xml then they are project directories too.
All project artifacts (artifacts resulting from projects) are stored in repositories. There are remote and local repositories. Local repository is created in ./maven/repository. In windows its "c:/Documents and Settings/
The structure of repository on a windows box:
c:/Documents and Settings/babu.subburathinam/maven/repository/commons-loggging/jars/commons-logging-1.0.7.jar
Instead of each project having a copy of its dependencies, all libraries are lodged in a repository and all projects share the libraries available in the repository. Each project will inturn publish its artifact on to the repository. This process of a project publishing its artifact is called "install"ing in maven lingo. This process of each project publishing its (snapshot and release) artifacts to a central repository helps in continuous integration. This is how: Daemon processes running in build servers can build each project with its updated dependencies several times a day, deploy and test the built artifacts. Thus, integration issues if any will surface much before the release date of a specific project.
Inputs to maven:
One of the input files to maven is Project Object Model (POM) file. This file describes the project to maven. This file has the following structure:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
Line 2 - Root element of XML
Line 3 - This tag is unused but needed.
Line 4 - A directory with this name is created in Maven repository to hold the artifacts of projects sharing the group id.
Line 5,6 - The id and version is used to create the artifact name as
Line 7 - Name of the project
The project Management section has project information such as the organization, its web site, location of SCM (Software configuration management), deployment and issue tracking sites, developer lists, mailing lists, etc...Most of this section is optional. The contents of project.xml can be extended. Most of the content is defined at the enterprise level and each project can override what is appropriate to it.
An example of the project management section:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 ...
30 ...
31
32
33
34
35
36
37
38
39 ...
40 ...
41
* Lines 01-05 - Organization details
* Line 08 - Top level package for the project
* Line 09 - Project Logo
* Line 12 - Project web site
* Line 14 - The site where the project is hosted
* Line 15 - Physical location of project deployment
* Line 16 - Physical location where the project distributions are available
* Lines 18-21 - SCM to access the project source
* Lines 23-31 - Mailing list for the project
* Lines 33-41 - Developers in the project
General structure of a maven project:
Maven Project Root
- maven.xml // Project definition file
- src // source directory
-- conf // Configuration within source
---xyz.properties // config gile
--java // java source
---com
----access
-----dev
------Hello.java
- test // test directory
-- conf // test configuration
---abc.properties // test config file
--java // java test files
---com
----access
-----dev
------TestHello.java
Project dependency section
In this section the project indicates all the dependecies that it has on artifacts of other projects. An example:
01
02
03
04
05
06
Line 1 - Starts the dependencies
Line 3 - The artifact that this project depends on is at the directory named "BeanUtils" in the repository
Line 4,5 - The artifact name is "commons-beanutils-1.5.jar" (using
Project build section
This section indicates the location of source, test and resource files. This is defined at the org. level or main project level for sub-projects to follow. If this section is not specified, no build ever gets done. Once build is over, all unit tests specified in the unit test section are executed. The contents of this section should match the actual layout of the code in the filesystem.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
* Line 02 - Email address to send notification about the build status
* Line 03 - Folder containing the source files for the project. The source can be java, jsp and so on.
* Line 04 - Directory containing the unit test files for the project.
* Lines 05-09 - The test file name pattern to run after the build is completed
* Lines 11-19 - Resources to be copied in case a jar is created.
Project reports sections
Once build is done, reports and documentation about the build are generated.
e.g.
Labels:
Maven
Subscribe to:
Posts (Atom)