Beruflich Dokumente
Kultur Dokumente
Java
SOA
BPM
ALM
.NET
AJAX
TSSJS
Today On TSS
Articles
Discussions
Topics
White Papers
Multimedia
RSS
Design/Architecture
SOA and service integration
REST Web services
ESB products
Software development
Application Integration middleware
Application security
Design for test
Data-oriented design
Java architecture for cloud
EJB
EJB specification
EJB containers
EJB troubleshooting
EJB programming
Java application servers
EJB products
Web Services
Web services architecture
WS* specifications
Web Applications
Web app frameworks
Spring framework
Hibernate framework
Java servlets
Java server pages
Ajax Web development
Rich Internet applications
Java server faces
Java Web portals
Other UI
Development
Java programming language
Software programming languages
JVM languages
DSLs
Java application deployment
Performance/Scalability
Software performance tools
Application performance measurement
Cloud/grid/memory systems
JVM
Application scalability
Tools
Eclipse development and tools
Open source tools
IDEs
Java EE
Java software testing
1 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
Development hardware
Site Index
THE AWARD-WINNING .NET REPORTING TOOL FOR VISUAL STUDIO:
14 YEARS AND COUNTING, AND IT JUST GOT BETTER
Home
>Topics
>Application and Web services development tools
>Java EE development utilities
>Setting Up a Maven Repository
Print
Email This
Digg This
Stumble
Delicious
1. Introduction
Maven is a popular build tool available for java developers. One of the benefits of maven is that helps to reduce the duplication of dependent software
libraries (jars) required to build an application. The maven suggested approach is to store all the software libraries in a remote store called a repository.
Maven synchronizes with the public repository at ibiblio.org This repository is slow, unreliable and does not have the latest versions of some libraries(jars)
available elsewhere. Libraries private to the organization cannot be uploaded there either. By setting up an internal maven repository, an organization can
avail of the benefits of a maven repository and bypass some of the shortcomings of the repository at ibiblio.
This article looks at some of the functionality that a maven repository should provide. Criteria for choosing a maven repository are listed. Steps involved in
setting up a maven repository using Artifactory are explained. The process of setting up the repository is same for both Linux and Windows and the minor
differences are highlighted in the article. Examples of maven ‘pom’ files which use this repository are shown. The article is illustrated with screenshots to
guide the user in setting up a repository. Sample maven and artifactory configuration is shown.
It is assumed that the reader is familiar with the following concepts and technologies:
Maven 2
JEE web servers deployment process (e.g. deploying web applications to Tomcat)
XML
The purpose of maven repository is to serve as an internal private repository of all software libraries used within an organization. Storing maven artefacts(jars
and poms) in a dedicated maven repository is preferable to storing them in version control systems(such as CVS or Subversion) for the following reasons:
Libraries(jars) are binary files and don’t belong in version control systems which are better at handling text files
Keeps the version control database small
Checkouts, updates and other actions on the version control system will be quicker
Local repository – exists on developers machine and is maintained by the developer. It is in sync with the maven repositories defined in the
2 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
‘settings.xml’ in their ‘~home/.m2’ folder. If no private remote internal repository is setup and listed in the pom.xml file or settings.xml file, then this
local repository on developers machine is synchronized with the public maven repository at ibiblio.org
Private remote internal repository – This the repository which we will setup. We will change the maven pom.xml or settings.xml to use this repository
Public remote external repository – This is the public external repository at ibiblio.org. By default, maven synchronizes with this repository.
3 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
Following review of all products, Artifactory has all the criteria that we are looking for. Proximity maven repository also seems to have most of the features
we are looking for. We will look at implementing the maven repository using Artifactory.
Artifactory – download and install from http://www.jfrog.org/sites/artifactory/latest/ Current latest release is 1.2.1-rc1. Artifactory comes with a web
application which can be installed into Tomcat
JDK 1.6 – see http://www.jfrog.org/sites/artifactory/latest/install.html for more information
Tomcat 6
Down load and unzip artifactory. The directory structure is shown below:
4 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
Backup – backup of repository. Backup policy can be setup using ‘cron’ expressions. Quartz scheduler is used to run the backup at the specified time.
The backup interval is specified in the ‘ARTIFACTORY_INSTALLATION_FOLDER>/etc/artifactory.config.xml’
Bin – batch files used to run the included jetty web server
Data – Has derby database files. Everything in this folder can be deleted if you wish to start with a clean repository. In a new installation of artifactory,
this folder is empty.
Etc – Configuration files for artifactory. Has ‘artifactory.config.xml’ and ‘jetty.xml ‘and ‘log4j.,properties’
Lib – has all the dependent jar files
Logs – log files
Webapps – has the ‘war’ file. This can be copied and installed in tomcat.
Once the web applications is deployed, the web application needs this information:
A single configuration is used to specify all 3. We only have to specify the location of the location of the artifactory installation folder during Tomcat startup
and artifactory will be able to work out the rest. An alternative to this approach would have been to setup connection to the derby database using jdbc and to
configure artifactory in the web application(by including artifactory.config.xml in the web application). However, this approach is simpler.
The location of artifactory installation folder can be specified as a environment variable. For Linux, use ‘.bash’ script to export the location of the artifactory
installation folder as shown below:
export JAVA_OPTS = -Dartifactory.home=/home/amangat/artifactory-1.2.1-rc1
A suggested approach is to create 3 repositories(or sub repositories) in our maven repository. They are:
Private-internal-repository: This repository contains artifacts which are used only within the organization. These are manually uploaded by the
5 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
developer. This does not synchronize with remote repository with ibiblio as the artifacts in this repository(or sub-repository) are private to the
organization.
3rd-party: This contains artifacts which are publicly available but not in ibiblio repository. Example could be latest versions of libraries which are not yet
available on ibiblio or jdbc drivers. This repository is not synchronized with ibiblio as ibiblio does not have these jars
Ibiblio-cache: This repository is synchronized with ibiblio repository and is a cache of the artifacts from ibiblio.
This is configured in the <ARTIFACTORY_INSTALLATION_FOLDER>/etc/artifactory.config.xml’. The configuration to setup these 3 repositories is shown
below:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://artifactory.jfrog.org/xsd/1.0.0"
xsi:schemaLocation="http://artifactory.jfrog.org/xsd/1.0.0
http://www.jfrog.org/xsd/artifactory-v1_0_0.xsd">
<!-- Backup every 12 hours -->
<!--<backupCronExp>0 0 /12 * * ?</backupCronExp>-->
<localRepositories>
<localRepository>
<key>private-internal-repository</key>
<description>Private internal repository</description>
<handleReleases>true</handleReleases>
<handleSnapshots>true</handleSnapshots>
</localRepository>
<localRepository>
<key>3rd-party</key>
<description>3rd party jars added manually</description>
<handleReleases>true</handleReleases>
<handleSnapshots>false</handleSnapshots>
</localRepository>
</localRepositories>
<remoteRepositories>
<remoteRepository>
<key>ibiblio</key>
<handleReleases>true</handleReleases>
<handleSnapshots>false</handleSnapshots>
<excludesPattern>org/artifactory/**,org/jfrog/**</excludesPattern>
<url>http://repo1.maven.org/maven2</url>
</remoteRepository>
</remoteRepositories>
</config>
Sign in using username ‘admin’ and password ‘password’. Click on the Browse repository link and you should be able to view the contents of the repository.
6 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
Maven uses the settings.xml file located at ‘~/.m2/settings.xml’ to get the location of maven repository. If no repository is specified, maven uses the default
repository which is at ibiblio.org. The settings.xml file has to be changed to use the new repository. The settings are shown below:
<profiles>
<profile>
<id>dev</id>
<properties>
<tomcat5x.home>C:/InstalledPrograms/apache-tomcat-5.5.20</tomcat5x.home>
</properties>
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8080/artifactory/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/repo</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://localhost:8080/artifactory/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/repo</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
The repository settings can also be done in the project pom.xml. A simple ‘pom.xml’ is shown below:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8080/artifactory/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/repo</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://localhost:8080/artifactory/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/repo</url>
7 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
When building the maven project, all the repositories should be downloaded using the new repository. The console will show the server maven uses as shown
below:
Login to the new repository using your web browser and you will see that artifactory has downloaded and cached the artifacts from ibiblio.
Artifacts can be installed using the web UI or using maven command line. Installation using the web UI is simple and faster and does not require any
configuration changes. Installation using the command line requires configuration changes in settings.xml and the it can be used in other scripts.
8 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
2. Artifactory will create the pom file if you are uploading a jar file. You can also specify which repository to upload to.
3. Once uploaded, the artifact appears in the repository along with the ‘pom’ file created by artifactory.
When using ‘mvn clean install’ command, maven only packages and installs the artifact to the local repository. To install it to the AHP internal repository, we
have to add an additional configuration section in the settings.xml. The steps involved are shown below:
<settings>
<servers>
<server>
<id>organisation-internal</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
</settings>
9 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
The repository id should match the server id defined in the settings.xml. The url should include the name of the repository the artefact is to be installed in.
The new artifact appears in the repository and artifactory has created the ‘pom’ file for us automatically.
Backup policy is specified in the <ARTIFACTORY_INSTALLATION_FOLDER>/etc/artifactory.config.xml. Backup schedule is specified using ‘cron’
expression. The backup configuration element is highlighted below:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://artifactory.jfrog.org/xsd/1.0.0"
xsi:schemaLocation="http://artifactory.jfrog.org/xsd/1.0.0
http://www.jfrog.org/xsd/artifactory-v1_0_0.xsd">
<!-- Backup every 12 hours -->
<backupCronExp>0 0 /12 * * ?</backupCronExp>
<localRepositories>
<localRepository>
<key>private-internal-repository</key>
<description>Private internal repository</description>
<handleReleases>true</handleReleases>
<handleSnapshots>true</handleSnapshots>
</localRepository>
<localRepository>
<key>3rd-party</key>
<description>3rd party jars added manually</description>
<handleReleases>true</handleReleases>
<handleSnapshots>false</handleSnapshots>
</localRepository>
</localRepositories>
<remoteRepositories>
<remoteRepository>
<key>ibiblio</key>
<handleReleases>true</handleReleases>
<handleSnapshots>false</handleSnapshots>
<excludesPattern>org/artifactory/**,org/jfrog/**</excludesPattern>
<url>http://repo1.maven.org/maven2</url>
</remoteRepository>
</remoteRepositories>
</config>
Backups are stored in ‘<ARTIFACTORY_INSTALLATION_FOLDER>/backups’. The backups are in the same format as the local repository on developers
machine. This makes it very easy to migrate the repository contents to another implementation of maven repository.
9. Conclusion
An internal private maven repository speeds up the build process and makes it easier to do clean builds. It also helps to avoid conflicts due to different
versions of libraries.
Amongst the 4 common maven repositories available, Artifactory seems to be the better product.
Artifactory makes it easy to setup a maven repository. It provides all the features which a good maven repository should implement. The organization will not
be locked into this tool as it is easy to migrate the repository contents to another implementation. A web UI makes the repository easy to use even for people
10 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
Biography
Avneet Mangat has 5 years experience in Java/J2EE, and is currently working as Lead developer at Active Health Partners (www.ahp.co.uk). He has a
Bachelor’s degree in Software Engineering, and is a Sun Certified Java programmer, Adobe certified Flash Designer and Prince2 certified (foundation). He is
the lead developer of open source tool DBBrowser, please see http://databasebrowser.sourceforge.net/ . His outside interests include photography and
traveling, and he can be contacted at avneet.mangat@ahp.co.uk or avneet.mangat@gmail.com.
Tags: Java EE development utilities, VIEW ALL TAGS
Digg This
Stumble
Delicious
Ads by Google
11 of 12 8/12/2010 6:38 AM
Setting Up a Maven Repository http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...
See also
Related Topics:
Site highlights:
About Us | Contact Us | For Advertisers | For Business Partners | Site Index | RSS
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective
purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.
All Rights Reserved, Copyright 2000 - 2010, TechTarget | Read our Privacy Statement
12 of 12 8/12/2010 6:38 AM