C6 Using Maven – Internal Repository Management

Install Archiva

 

If you are using Maven in a corporate environment, then you probably need a repository manager. There are few program such as Archiva , Proximity or Maven Proxy are out there for options. For this article, I will use Archiva for demostration. Please check the refence below for more details about why choosing Archiva

 

A Maven repository manager acts as both a repository for your JAR files, and a proxy/cache between you and all those dodgy public repositories out there on the internet. So, when Maven asks for a new dependency, its first port of call is your local repository. If the JAR has already been downloaded, it will be stored in the Archiva repository, and you won’t need to download it from the internet. This is both faster and more reliable than downloading JAR files directly from the internet.

 

You can download Archiva from http://maven.apache.org/archiva/download.html for your preference. In this article, I will only briefly introduce how to install and use the web application.

 

  • Create a directory in tomcat called archiva, at the same level as bin, conf, logs and the others.
  • Copy the war file into the new directory
  • Create a conf/Catalina/localhost/archiva.xml file with the following data (replace the database paths with a suitable location)

<?xml version="1.0" encoding="UTF-8"?>

 <Context path="/archiva"

          docBase="${catalina.home}/archiva/apache-archiva-1.0.2.war">

 

 <Resource name="jdbc/users" auth="Container" type="javax.sql.DataSource"

           username="sa"

           password=""

           driverClassName="org.apache.derby.jdbc.EmbeddedDriver"

           url="jdbc:derby:/path/to/database/users;create=true" />

 

 <Resource name="jdbc/archiva" auth="Container" type="javax.sql.DataSource"

           username="sa"

           password=""

           driverClassName="org.apache.derby.jdbc.EmbeddedDriver"

           url="jdbc:derby:/path/to/database/archiva;create=true" />

 

 <Resource name="mail/Session" auth="Container"

            type="javax.mail.Session"

            mail.smtp.host="localhost"/>

 </Context>

  • Download the derby library for database management, mail library for email management and save them into common/lib directory
  • The $appserver.base java property is used by the Archiva internal logging configuration to determine where to output its logs to. Open the Catalina.bat file and insert the following code into the line start with set JAVA_OPTS=%JAVA_OPTS%

-Dappserver.home=$CATALINA_HOME -Dappserver.base=$CATALINA_HOME

 

The last two steps could be optional, if you only expect Archiva to provide an HTTP access of the repository.

 

Configure Archiva

Run your tomcat application server and set up your account information. Then you need to redirect your WebDAV URL to the directory of your internal repository.

           

With Archiva, you can also add additional repositories. The accessible URL will in the following format

http://%5BURL TO ARCHIVA]/repository/[REPOSITORY ID]

(e.g. http://localhost:8080/archiva/repository/releases).

 

Add your Repository to maven

Your repository can be simply added by inserting the following tag into either your pom or settings file.

<repository>

              <id>Mycompnay internal</id>

              <url>http://10.40.32.44:8888/archiva/repository/internal/</url>          

</repository>

 

Alternatives

If you think Archiva brought you too much work to manage your repository (although I would never agree), you can simply added your repository directory to the maven configuration file. Note: It is double backward slashes.

 

<repository>

              <id>Mycompnay internal </id>

              <url>file:\\computerName/repositoryName</url>

</repository>     

 

 

Reference:

http://maven.apache.org/archiva/docs/1.0.2/adminguide/webapp.html

http://java.dzone.com/blogs/mrjohnsmart/2008/02/19/maven-repository-managers-why-

 

 

Advertisements
This entry was posted in Maven. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s