How to create Maven 2 repository in your LAN

in

Maven is my new development tool in Java world. I used to use Ant. But the build.xml and the jar management often make me crazy. Why bothers to bring along your jars in the project as you move into another PC. Or, why bothers to have duplicated jar in you PC as you get more projects? Why don't share them among the projects? So, I try maven 2.

Since Maven use remote repository by default, I think it is easier for developers in my office to have local repository to cache jars from remote repository. This urged me since I also have set up a local debian repository in my office (apt-cacher).

Ok, lets start configuring artifactory which I think it's the best repository server.

Assumption: The developer's PC has Maven 2 installed

In Repository server

  1. Download artifactory-x.y.z.zip in http://www.jfrog.org/download.php. This distribution contains built-in Jetty server.
  2. Extract into /opt directory so you'll see /opt/artifactory-x.y.z/artifactory.jar
  3. Install as service
    cd /opt/artifactory-x.y.z/bin
    sudo ./install.sh
    

You may need to add JAVA_HOME in the service by adding line

. /etc/environment

in line 48 of /etc/init.d/artifactory. The /etc/environment file should contain

JAVA_HOME=/usr/lib/jvm/java-6-sun

or others which specify your JAVA_HOME

In a developer PC with installed Maven

Change Maven global repository:

  1. Create new profile in $M2_HOME/conf/settings.xml
    <profile>
    	<id>artifactory-repository</id>
    	<repositories>
    		<repository>
    			<id>central</id>
    			<url>http://192.168.1.2:8081/artifactory/repo</url>
    			<snapshots>
    				<enabled>false</enabled>
    			</snapshots>
    		</repository>
    		<repository>
    			<id>snapshots</id>
    			<url>http://192.168.1.2:8081/artifactory/repo</url>
    			<releases>
    				<enabled>false</enabled>
    			</releases>
    		</repository>
    	</repositories>
    	<pluginRepositories>
    		<pluginRepository>
    			<id>central</id>
    			<url>http://192.168.1.2:8081/artifactory/plugins-releases</url>
    			<snapshots>
    				<enabled>false</enabled>
    			</snapshots>
    		</pluginRepository>
    		<pluginRepository>
    			<id>snapshots</id>
    			<url>http://192.168.1.2:8081/artifactory/plugins-snapshots</url>
    			<releases>
    				<enabled>false</enabled>
    			</releases>
    		</pluginRepository>
    	</pluginRepositories>
    </profile>
    
  2. Activate this profile by adding in the same settings.xml file
    <activeProfiles>
      <activeProfile>artifactory-repository</activeProfile>
    </activeProfiles>
    

Have fun with your new Maven local repository
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <pre> <i>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.