Saturday 22 February 2014

Maven and Archiva setup

Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central place.
I've found Maven very useful in many situation, for example for building up a project downloaded from internet and compile it straight away. With Maven it takes 2 minutes only!!!

Here a brief guide about how to setup Maven+Archiva


Maven Installation

1. Download Maven 2.2.1 Maven Download

2. Unpack the archive where you would like to store the binaries. A directory called "apache-maven-2.x.y" will be created.

3. Add the bin directory to your PATH, eg:

      set PATH="c:\apache-maven-2.x.y\bin";%PATH%

4. Make sure JAVA_HOME is set to the location of your JDK

5. Run "mvn --version" to verify that it is correctly installed.


Archiva Installation

1. The quickest way to install Archiva is to download archiva standalone and use this distribution. This includes a bundled Jetty server which can be easily started.

2. Unpack the archive where you would like to store the binaries. A directory called "apache-archiva-2.x.y" will be created.

3. Archiva can be run by executing, bin/archiva, or bin\archiva.bat for Windows (select the one for your environment). The argument can be console to run interactively, or start to run in the background (in this case, run the script with stop to later stop the server). The logs are available in the logs directory where Archiva is installed.

Maven Configuration

Maven configuration occurs at 3 levels:

-Project - most static configuration occurs in pom.xml
-Installation - this is configuration added once for a Maven installation
-User - this is configuration specific to a particular user (${user.home}/.m2/settings.xml)

The separation is quite clear - the project defines information that applies to the project, no matter who is building it, while the others both define settings for the current environment.

The localRepository is the path to the local repository maven will use to store artifacts. It has to be configured using a local folder like here:

<localRepository>C:\apache-maven\localRepo</localRepository>

Repositories are declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box. However, you may want to use an alternative mirror for a particular repository without changing the project files.

If you would like Archiva to serve as the only repository used by your Maven installation, you can use the Maven mirror settings to force this behaviour.
First, you need to select the default repository to use when none is configured by adding the following to the settings.xml file:


  
  <mirrors>
    <mirror>
      <id>archiva.default</id>
      <url>http://repo.mycompany.com:8080/repository/internal/</url>
      <mirrorOf>external:*</mirrorOf>
    </mirror>
  </mirrors>

Archiva Configurations

You can now browse the web administration of Archiva. There will be a few basic setup tasks to get started.

The first step is to setup your administration user. The password requires a numerical character and must not be longer than 8 chars. You'll then need to log in. Use 'admin' as the username and the password you've entered.

At this point, Archiva is fully functional - you can use it with the default repositories and guest user. You might like to explore the user and administrator guides to find other functionality.

The default configuration for Archiva configures two repositories:

  • internal - a repository for containing released artifacts. This is connected by proxy to the central repository, so requests here will automatically retrieve the remote artifacts.
  • snapshots - a repository for storing deployed snapshots. This is not proxied to any remote repositories by default.
In addition, the guest user has read access to these repositories, so you can make anonymous requests to either. To try this out, point a web browser at the following URL: http://localhost:8080/repository/internal/junit/junit/3.8.1/junit-3.8.1.jar. Though the artifact is not present locally, you will see in the Archiva logs that it is downloaded from the central repository, and then handed back to the browser and downloaded from Archiva. Future requests for the artifact will be much faster as they need not be downloaded from the central repository

No comments:

Post a Comment