Sunday, August 29, 2010

Generate POM files for a 3rd party artifact in Maven

Maven is a popular software project management tool. It is used heavily for building you project deliverables. More information about maven can be found here.

Maven works on the dependency concept. It essentially means that every project should identify its required artifacts. These artifacts can be found in repositories. Repository is a central place where you keep all your required jars (or other resources). There is a specific structure required to put your artifacts into the repository. We can not just copy every thing at same place. To identify a resource through dependency mentioned in pom.xml, maven looks for the specific structure. Also ther should be a .POM file at the same location of the artifact.

Normally the artifacts generated by maven build comes with the POM for it. So that, any other project wanting to use this artifact can do that. But if the artifact is created from a build other than maven (e.g. ant, Makefile etc), it will not have the POM generated. So this artifact can not be readily used by maven. We need to use the below command to generate a POM for a 3rd party artifact which does not come with a POM by default.

mvn install:install-file -DgroupId=group-id \
                         -DartifactId=artifact-id \
                         -Dversion=version \
                         -Dpackaging=packaging \
                         -Dfile=fileToInstall \

Here groupId is a string that identifies the product group. artifactId is the string to identify the artifact from its group. version is the artifact version. packaging is the file type of the artifact (e.g. jar). file attribute holds the complete path to the artifact in your local system. generatePom attribute creates the POM for this artifact.

This command will create the required directory structure for your 3rd party artifact and generate a POM for it. The output will be copied to your local repository. Now you can use this dependency in your POM to build your project.

No comments:

Post a Comment