Setting Up a Maven Repository

http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repos...

Java Development Activate your FREE membership today | Log-in 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

. unreliable and does not have the latest versions of some libraries(jars) available elsewhere.1 Background knowledge It is assumed that the reader is familiar with the following concepts and technologies: Maven 2 JEE web servers deployment process (e. 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. The process of setting up the repository is same for both Linux and Windows and the minor differences are highlighted in the article. 1.g. an organization can avail of the benefits of a maven repository and bypass some of the shortcomings of the repository at ibiblio. Development hardware SEARCH this site and the web Site Index THE AWARD-WINNING .Setting Up a Maven Repository http://www. One of the benefits of maven is that helps to reduce the duplication of dependent software libraries (jars) required to build an application. Introduction Maven is a popular build tool available for java developers. The maven suggested approach is to store all the software libraries in a remote store called a repository. deploying web applications to Tomcat) XML 1.com/news/1364121/Setting-Up-a-Maven-Repos.4 Types of maven repository 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 . updates and other actions on the version control system will be quicker 1.NET REPORTING TOOL FOR VISUAL STUDIO: 14 YEARS AND COUNTING. Maven synchronizes with the public repository at ibiblio. Criteria for choosing a maven repository are listed. 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. Libraries private to the organization cannot be uploaded there either.org This repository is slow. This article looks at some of the functionality that a maven repository should provide.3 Advantages of having an internal private repository: Reduced likelihood of version conflicts Less manual intervention required for doing a build first time A single central reference repository of all dependent software libraries rather than several independent local libraries It is quicker to do a clean build when using an internal repository as maven artifacts are retrieved from a server on the intranet rather than the ibiblio server on the internet 1. Sample maven and artifactory configuration is shown. Steps involved in setting up a maven repository using Artifactory are explained.com Digg This Stumble Delicious 1.theserverside. AND IT JUST GOT BETTER Powered by Google Home >Topics >Application and Web services development tools >Java EE development utilities >Setting Up a Maven Repository Print Email This Java Development News: Setting Up a Maven Repository By Avneet Mangat 01 Jun 2007 | TheServerSide..2 Purpose of maven repository The purpose of maven repository is to serve as an internal private repository of all software libraries used within an organization. By setting up an internal maven repository.

maven synchronizes with this repository. This would not be synchronised with an external repository.g.xml file or settings.m2’ folder.theserverside. Use cases for maven repository Create 2 sub-repositories within the internal repository ‘Ibiblio-cache’ for artefacts downloaded from ibiblio.. another sub-repository can be created for artefacts available publicly but not in ibiblio – e. ‘settings. preferably using a web browser Search for artefacts in the repository Download code from version control. then this local repository on developers machine is synchronized with the public maven repository at ibiblio.org and available publicly..com/news/1364121/Setting-Up-a-Maven-Repos.xml’ in their ‘~home/. later versions of some artefacts. If no private remote internal repository is setup and listed in the pom. Criteria for choosing a maven repository implementation The ideal maven repository implementation should be: Open source and free Provide admin tools Provide a repository browser – preferably web browser rather than desktop application.xml file.2 Development environment with an organization wide internal remote repository 3.xml or settings.1 Development environment without any repository 2.g Apache or Tomcat 3 of 12 8/12/2010 6:38 AM . We will change the maven pom.org.org Private remote internal repository – This the repository which we will setup. Overview of maven repository 2. This is not synchronized with any external repository and contains artefacts which are unique to the orgranization Alternatively. 2. Deployable in standard web server – e. By default.xml to use this repository Public remote external repository – This is the public external repository at ibiblio. This would be synchronized with external repository from ibiblio internal-maven-repository – for organizations internal artefacts.Setting Up a Maven Repository http://www. We can call this ‘3rd-party’ Browse remote repository. change ‘settings.xml’ to point to the internal repository and do a clean build without any manual intervention Install new version of an artefact Bulk import artefacts into the repository Bulk export artefacts from the repository Backup the repository manually and setup task to do this automatically 4.

de/dsmp/ Proximity . but not configurable No Proximity Yes Yes Yes Artifactory Yes Yes Yes(works in Tomcat and bundled with Jetty) Yes Yes Yes(Ajax web UI) Yes(using Java quartz API and ‘cron’ expressions) Jira issue tracker.jfrog. The directory structure is shown below: 4 of 12 8/12/2010 6:38 AM . Proximity maven repository also seems to have most of the features we are looking for.pdark.1-rc1.http://maven-proxy.codehaus.org/ Artifactory . Other points about Artifactory are: Meets all our requirements Apache 2.g.6 – see http://www.http://proximity. Uses Derby DB to store artefacts.abstracthorizon. IRC Yes No No. forums and other sources of information Yes No Yes No Jira.Setting Up a Maven Repository http://www.org/sites/artifactory/latest/ A comparison is shown below: Standard maven repository Dead simple Maven Proxy (DSMP) No Basic Basic No Yes..org/sites/artifactory/latest/install.6 and Tomcat 6. Ability to create. We will look at implementing the maven repository using Artifactory.2 Directory structure Down load and unzip artifactory. It also makes upgrades of maven repository very easy Compliant with Java Content Repository standard (JSR-170).0 license Runs on JDK 1. build from source No No Yes No Yes No Wiki and issues tracker Following review of all products. Artifactory has all the criteria that we are looking for. forums and other independent sources of information Active community/developers so that the produce is enhanced and bugs fixed 5. Tomcat or Jetty) Create. Good documentation on site Admin tools Repository browser Deployable in standard web server (e.2.1 Required software Artifactory – download and install from http://www. Uses Lucene as search engine.. Setting up the maven repository 6. Artifactory comes with a web application which can be installed into Tomcat JDK 1. Data is stored in a published and well known format All artefacts can be bulk exported to local repository and then imported into some other repository so it is easy to move artefacts from one implementation to another.jfrog.org/sites/artifactory/latest/ Current latest release is 1. edit and delete sub repositories Bulk import/export facility to move groups of artefacts into and out of the repository Access control facility and anonymous read-only access Easy to setup and use Backup facility Issue tracker.theserverside.jfrog.http://www. Comparison of various maven repositories Some of the popular open source and free maven repositories are: Standard maven proxy from codehaus .html for more information Tomcat 6 6. Repository is indexed and can be re-indexed UI done using Ajax Easy to customise the UI Uses Jira as an issue tracker 6.com/news/1364121/Setting-Up-a-Maven-Repos. edit and delete sub repositories Bulk import/export artefacts Easy to setup and use Backup facility Issue tracker.org/ Dead simple Maven Proxy (DSMP) .http://www. Artifactory is deployed as a ‘war’ file in Tomcat.

properties’ Lib – has all the dependent jar files Logs – log files Webapps – has the ‘war’ file. For Linux.. No tomcat configuration changes are required with jdk1.xml in the web application).6 and Tomcat 6. These are manually uploaded by the 5 of 12 8/12/2010 6:38 AM . 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. 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.1-rc1 For Windows. Backup policy can be setup using ‘cron’ expressions. This can be copied and installed in tomcat. this folder is empty.config.com/news/1364121/Setting-Up-a-Maven-Repos. use ‘.bash’ script to export the location of the artifactory installation folder as shown below: export JAVA_OPTS = -Dartifactory. Has ‘artifactory.xml’ Bin – batch files used to run the included jetty web server Data – Has derby database files. The location of artifactory installation folder can be specified as a environment variable.config. 6. this approach is simpler.config. Etc – Configuration files for artifactory. The backup interval is specified in the ‘ARTIFACTORY_INSTALLATION_FOLDER>/etc/artifactory. In a new installation of artifactory.3 Setup the maven repositories A suggested approach is to create 3 repositories(or sub repositories) in our maven repository. it can be added to Tomcat startup options as shown below: 6.home=/home/amangat/artifactory-1. Tomcat 6 should detect the web application and deploy it.xml’ and ‘jetty.. Quartz scheduler is used to run the backup at the specified time. The folders are: Backup – backup of repository. However.xml ‘and ‘log4j.2 Deploy in Tomcat 6 Deploy the ‘war’ file in ‘<ARTIFACTORY_INSTALLATION_FOLDER>/webapp’ to ‘<TOMCAT_INSTALLATION_FOLDER>/webapps’. Everything in this folder can be deleted if you wish to start with a clean repository. the web application needs this information: Location of the database to store the artefacts Location of the artifactory config xml file Location of backup folder A single configuration is used to specify all 3.. They are: Private-internal-repository: This repository contains artifacts which are used only within the organization.2. Once the web applications is deployed.Setting Up a Maven Repository http://www.theserverside.

jfrog. developer.com/news/1364121/Setting-Up-a-Maven-Repos. The configuration to setup these 3 repositories is shown below: <config xmlns:xsi="http://www.0.jfrog. This is configured in the <ARTIFACTORY_INSTALLATION_FOLDER>/etc/artifactory.org/jfrog/**</excludesPattern> <url>http://repo1.0 http://www.0.w3.xsd"> <!-. Example could be latest versions of libraries which are not yet available on ibiblio or jdbc drivers.org/2001/XMLSchema-instance" xmlns="http://artifactory.config. Click on the Browse repository link and you should be able to view the contents of the repository. 3rd-party: This contains artifacts which are publicly available but not in ibiblio repository.jfrog. 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.org/maven2</url> </remoteRepository> </remoteRepositories> </config> Start Tomcat and navigate to http://localhost:8080/artifactory The artifactory home page is shown below: Sign in using username ‘admin’ and password ‘password’.0" xsi:schemaLocation="http://artifactory.org/xsd/artifactory-v1_0_0.org/xsd/1.maven.org/xsd/1.Setting Up a Maven Repository http://www. This does not synchronize with remote repository with ibiblio as the artifacts in this repository(or sub-repository) are private to the organization.. 6 of 12 8/12/2010 6:38 AM ..theserverside.xml’.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/**.

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> 7.xml file located at ‘~/.theserverside.5..org/POM/4.apache.0" xmlns:xsi="http://www.0.m2/settings.xml. The settings. If no repository is specified.apache.apache.xml Maven uses the settings.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 .xml file has to be changed to use the new repository.0</modelVersion> <groupId>test</groupId> <artifactId>test</artifactId> <packaging>jar</packaging> <version>1. maven uses the default repository which is at ibiblio.1 Configure maven using settings.Setting Up a Maven Repository http://www.w3.xml’ is shown below: <project xmlns="http://maven..xml’ to get the location of maven repository.2 Configure maven using project ‘pom.com/news/1364121/Setting-Up-a-Maven-Repos. The settings are shown below: <profiles> <profile> <id>dev</id> <properties> <tomcat5x.org/maven-v4_0_0.0-SNAPSHOT</version> <name>test</name> <url>http://maven.org/POM/4. A simple ‘pom.org.0.0.xml’ The repository settings can also be done in the project pom.home>C:/InstalledPrograms/apache-tomcat-5.apache. Configuring maven to use the new repository 7. 7.20</tomcat5x.xsd"> <modelVersion>4.0 http://maven.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.

.3 Building using the new maven repository When building the maven project. 7.4 Installing artefacts to the repository Artifacts can be installed using the web UI or using maven command line.8. 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.Setting Up a Maven Repository http://www. Upload the artifact to deploy (‘jar’ file or ‘pom’ file) 8 of 12 8/12/2010 6:38 AM . <releases> <enabled>false</enabled> </releases> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3. 7. all the repositories should be downloaded using the new repository.com/news/1364121/Setting-Up-a-Maven-Repos.1</version> <scope>test</scope> </dependency> </dependencies> </project> 7. Installation using the web UI is simple and faster and does not require any configuration changes.1 Installing artifacts using the web UI The steps involved are shown below: 1.theserverside. Installation using the command line requires configuration changes in settings.xml and the it can be used in other scripts..4.

You can also specify which repository to upload to.xml. maven only packages and installs the artifact to the local repository. we have to add an additional configuration section in the settings.1 Installing artifacts from maven command line When using ‘mvn clean install’ command.theserverside.Setting Up a Maven Repository http://www. 3. the command is: mvn deploy:deploy-file -DrepositoryId=organisation-internal -Durl=http://localhost:8080/artifactory/private-internal-repository 9 of 12 8/12/2010 6:38 AM .. Once uploaded. To install it to the AHP internal repository. 7.4.com/news/1364121/Setting-Up-a-Maven-Repos. The steps involved are shown below: <settings> <servers> <server> <id>organisation-internal</id> <username>admin</username> <password>password</password> </server> </servers> </settings> To install an artefact to internal maven repository. the artifact appears in the repository along with the ‘pom’ file created by artifactory. 2.. Artifactory will create the pom file if you are uploading a jar file.

org/xsd/artifactory-v1_0_0..jfrog.xml. The backup configuration element is highlighted below: <config xmlns:xsi="http://www.org/maven2</url> </remoteRepository> </remoteRepositories> </config> Backups are stored in ‘<ARTIFACTORY_INSTALLATION_FOLDER>/backups’. 8. It also helps to avoid conflicts due to different versions of libraries.maven.0.Setting Up a Maven Repository http://www.1 -Dpackaging=jar -Dfile=target/test-1. A web UI makes the repository easy to use even for people 10 of 12 8/12/2010 6:38 AM .jfrog. Backup schedule is specified using ‘cron’ expression. This makes it very easy to migrate the repository contents to another implementation of maven repository. Other features of Artifactory 8. Amongst the 4 common maven repositories available.w3.jar The repository id should match the server id defined in the settings.2 Other features Delete artifacts using the web UI Search for artifacts using the web UI Bulk import/export all artifacts in repository The included jetty web server can be used if tomcat is not required 9. The organization will not be locked into this tool as it is easy to migrate the repository contents to another implementation. It provides all the features which a good maven repository should implement.org/xsd/1.org/jfrog/**</excludesPattern> <url>http://repo1. The new artifact appears in the repository and artifactory has created the ‘pom’ file for us automatically.0" xsi:schemaLocation="http://artifactory.config.org/2001/XMLSchema-instance" xmlns="http://artifactory.0. 8.. -DgroupId=test -DartifactId=test -Dversion=1.com/news/1364121/Setting-Up-a-Maven-Repos.xml.1 Backup the repository Backup policy is specified in the <ARTIFACTORY_INSTALLATION_FOLDER>/etc/artifactory.xsd"> <!-. Artifactory makes it easy to setup a maven repository.0 http://www. The url should include the name of the repository the artefact is to be installed in. The backups are in the same format as the local repository on developers machine.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/**. Conclusion An internal private maven repository speeds up the build process and makes it easier to do clean builds. Artifactory seems to be the better product.jfrog.org/xsd/1.1.theserverside.

VIEW ALL TAGS Digg This Stumble Delicious Java RELATED LINKS Ads by Google Managed Server HostingCost Effective Dedicated ServerHosting. net.com/news/1364121/Setting-Up-a-Maven-Repos. php.uk or avneet.com/Indian-ISO-Company/ QA at SlideShare DelhiStrong focus on automatedintegration testing w/Seleniumwww.www. who don’t know how the repository works.mangat@ahp.Setting Up a Maven Repository http://www.CtrlS.. Adobe certified Flash Designer and Prince2 certified (foundation). builder2GBHosting.AutomationAnywhere.. Tags: Java EE development utilities. and is currently working as Lead developer at Active Health Partners (www.com.co. 24/7 Live Support. He has a Bachelor’s degree in Software Engineering. 24x7 LIVE Supporthtml.uk).mangat@gmail.com Most reliable Web Hosting2GB for 39/mo.in Remote Backup SolutionSafely Backup to Remote DevicesThat You Control. asp. manage & automateSoftware Testing. He is the lead developer of open source tool DBBrowser. Free Trial!www.ahp. His outside interests include photography and traveling.sourceforge.co.slideshare.theserverside. flash. Biography Avneet Mangat has 5 years experience in Java/J2EE. and is a Sun Certified Java programmer.LogMeIn.net/ . Free Trial!www. and he can be contacted at avneet. please see http://databasebrowser.net Automated Software TestEasily create.com/Testing 11 of 12 8/12/2010 6:38 AM .

theserverside.0 security best practices Evil Design Patterns Get e-mail updates Submit your e-mail below to receive Java-related news.com/news/1364121/Setting-Up-a-Maven-Repos.from developing strategy. part 2 (Article) TSS Java Symposium conference coverage 2005 (Article) New Features in JGroups 2. Copyright 2000 .. SEARCH 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 . Java EE development utilities News. TechTarget | Read our Privacy Statement TechTarget . to making cost-effective purchase decisions and managing their organizations' technology projects . delivered to your inbox. events and online magazines.5 (Article) View more See also Related Topics: Eclipse development and tools.Day 4 (Article) Java Open Source Programming (Article) Dependency injection in Java EE.with its network of technology-specific websites. TechTarget Corporate Web Site | Media Kits | Reprints | Site Map All Rights Reserved.Integrated development environments Site highlights: Web 2. Open source software testing tools..Setting Up a Maven Repository http://www.The IT Media ROI Experts 12 of 12 8/12/2010 6:38 AM .2010. tech tips and more. tips & more TheServerSide at JavaOne 2003 . IDEs .

Sign up to vote on this title
UsefulNot useful