!!! Maven


[{TableOfContents}]


!! Resources

* [Home|http://maven.apache.org/]
* [Dependency mechanism|http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies]
* [Plugins|http://maven.apache.org/plugins/index.html]
* [pom reference|http://maven.apache.org/pom.html]

!! Eclipse integration

I installed the Eclipse QE plugin by adding [http://q4e.googlecode.com/svn/trunk/updatesite-iam/] to the list of software sites and check the Core features plus the Eclipse IAM editor

__Create maven project__

By hand it can be done with :
%%small
{{{
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
}}}
%%

Of use Eclipse New Project....



!! Dependencies

I have a dependency on x.y.z., how do I know the artifactid, groupID and version of it ?\\
A very brute way would be to search for pom files in the repository :
{{{
metskem@gneisenau:~$ find .m2/repository/ -name *.pom|wc
    384     384   32808
}}}
In a pom file you will find what you need :
%%prettify
{{{
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>commons-lang</groupId>
  <artifactId>commons-lang</artifactId>
  <name>Lang</name>
  <version>2.1</version>
  <description>Commons.Lang, a package of Java utility classes for the
    classes that are in java.lang's hierarchy, or are considered to be so
    standard as to justify existence in java.lang.</description>
  <url>http://jakarta.apache.org/commons/${pom.artifactId.substring(8)}/</url>
  <issueManagement>
................
}}}
%%


! Create repository entry

I have a project that requires WebSphere jars for compile, how do I arrange that with maven dependencies, I could not find a dependency for that (of course).\\
You can make it yourself with the install plugin :
%%small
{{{
metskem@gneisenau:~$ mvn install:install-file -Dfile=/home/metskem/java_libs/com.ibm.ws.admin.client_7.0.0.jar -DgroupId=com.ibm.websphere -DartifactId=admin.client -Dversion=7.0.0 -Dpackaging=jar -DgeneratePom=true
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'install'.
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file {execution: default-cli}]
[INFO] Installing /home/metskem/java_libs/com.ibm.ws.admin.client_7.0.0.jar to /home/metskem/.m2/repository/com/ibm/websphere/admin.client/7.0.0/admin.client-7.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Sat Oct 02 13:26:08 CEST 2010
[INFO] Final Memory: 4M/52M
[INFO] ------------------------------------------------------------------------
}}}
%%

! war plugin

If you want a war file to be generated by maven, you need the (default supplied) war plugin.\\
I had to add the webXml attribute to specify the location of the web.xml file, this can be done in the pom.xml, see the following snippet:\\
%%prettify
{{{

      <plugin>
      	<groupId>org.apache.maven.plugins</groupId>
      	<artifactId>maven-war-plugin</artifactId>
      	<version>2.0</version>
      	<extensions>false</extensions>
      	<inherited>true</inherited>
      	<configuration>
      	  <webXml>WebContent/WEB-INF/web.xml</webXml>
      	</configuration>
      </plugin>
}}}
%%