NOTE: AVOID SPACES IN DIRECTORY NAMES AT ALL COST!

It is mandatory that your JDK be installed in a directory that does NOT have spaces. The default installer uses “C:\Program Files\Java\**” and I just put mine in “c:\Java\**” instead.

Local Repository

Your “c:\Documents and Settings\[userId]\.m2\settings.xml” is the location where you can override various project properties. And YES, this is the only exclusion to the above directory name rule.

The first property is going to be the location of your local maven repository

<settings>
<localRepository>c:/opt/.m2/repository</localRepository>
</settings>

I like to put mine in a directory that has no spaces in the directory names such as “Documents and Settings” which is ok for Windows installations, but not for unix or Linux. I also like to have a standard place for my entire team to keep their local repository.

Offline

Determines whether maven should attempt to connect to the network when executing a build. This will have an effect on artifact downloads, artifact deployment, and others.

Proxies

This is a list of proxies which can be used on this machine to connect to the network. Unless otherwise specified (by system property or command-line switch), the first proxy specification in this list marked as active will be used.

Servers

This is a list of authentication profiles, keyed by the server-id used within the system. Authentication profiles can be used whenever maven must make a connection to a remote server.

I use this setting for accessing Archiva via WEBDAV:

<server>
<id>repository.webdav</id>
<username>[userId]</username>
<password>[password]</password>
</server>

Assuming you have the userId and the password correct, you should be able to download, and upload artifacts to your Archiva Repository.

But if I want to give my team read-only access to the same repository, I use guest with no password:

<server>
<id>repository.webdav</id>
<username>guest</username>
<password></password>
</server>

Mirrors

If I want my developers to only use our internal local repository, I will create a mirror setting:

<mirror>
<id>mirror.internal</id>
<url>http://192.168.1.119:8080/archiva/repository/internal/</url>
<mirrorOf>*</mirrorOf>
</mirror>

Profiles

This is the most important section here. I use this to override several different sections for each project. I like to call this profile local as the default. You can also create more profiles such as build, stage, qa, prod. This way, the operations or build master can control more specific build information and passwords.

<profile>
<id>local</id>
<properties>

I use project root so that I have a base directory in order to reference some resources on a local developer machine.

<projectRoot>C:/opt/servepath</projectRoot>

SCM information can be added by each developer with these 3 properties

<scmUsername>myUsername</scmUsername>
<scmPassword>myPassword</scmPassword>
<scmConnection>scm:svn:http://myOtherHost.com/svn/repos/mySVN</scmConnection>

I like to deploy my site documentation locally to the temp directory. This way I can look at my code metrics during my build cycle.

<siteUrl>file:///c:/opt/temp/site/${pom.version}</siteUrl>

The servers where mentioned above, but the repositoryUrl and snapshotRepositoryUrl allow each profile to override where the generated artifacts are going to get deployed to.

<repositoryUrl>http://myOtherHost.com:8080/archiva/repository/internal</repositoryUrl>
<snapshotRepositoryUrl>http://myOtherHost.com:8080/archiva/repository/internal</snapshotRepositoryUrl>

By setting the filter.file here, this allows each developer and each profile to select a different filter. This is a great way to have different build settings for different environments like build, stage, qa, and prod.

<filter.file>c:/opt/servepath/src/main/filters/filter-local.properties</filter.file>

Another important property for Test Drive Development, is the ability to change the database you want to test against. While there are several profiles in the root:: pom.xml, the url’s and credentials are generic. So I felt I needed to give the developer the opportunity to override those 3 items here:

<!– these settings must be the same as the selected activeProfile Database below –>
<jdbc.url><![CDATA[jdbc:mysql://myOtherHost.com:3306/testdb]]></jdbc.url>
<jdbc.username>myUser</jdbc.username>
<jdbc.password>myPassword</jdbc.password>

That is all for a single profile

</properties>
</profile>

Active Profiles

Active Profiles are used to set the various profiles the developer wants to run. Below we have local as the only profile selected. If you want to also run against tomcat5.5 and mysql, all you need to do is uncomment tomca5.5 and mysql below

<!–======= Environment Specific =================================–>
<activeProfile>local</activeProfile>

<!–======= Choose one of container ===============================–>
<!–<activeProfile>tomcat5.5</activeProfile>–>
<!–<activeProfile>jetty</activeProfile>–>

<!–======= Choose one of databases ==============================–>
<!–<activeProfile>mysql</activeProfile>–>
<!–<activeProfile>derby</activeProfile>–>
<!–<activeProfile>h2</activeProfile>–>

A full template version of a settings.xml from above is located at http://baselogic.com/maven/settings-template.xml

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting. http://www.baselogic.com/blog/resume

View all posts

Java / JavaEE / Spring Boot Channel

BLiNC Supporters

BLiNC Adsense

Archives

Newsletter