Software Development
Migrating your project to Maven 2 – Part II Lars Vonk 06 Mar, 2006
Maven Snapshots https://snapshots.maven.codehaus.org/maven2/ true falseThe findbugs plugin is missing the dependency to jaxen. The following dependency must be added in the pom.xml of the (MAVEN_REPO/findbugs/core-plugin/0.9.3/pom.xml).
jaxen jaxen 1.1-beta-7I tried to add it in my own pom.xml but that did not work.The difference between configuring plugins for maven 2 in contrast to maven 1.x is that now all your configuration goes in the pom.xml (or the settings.xml). For instance in maven 1.x you had to define the location of the license file for the clover plugin in the project.properties like this:
maven.clover.license.path=${maven.repo.local}/clover/licenses/clover-xebia.license
And the execution of clover could be defined in maven.xml as a pre goal like this:As you know the project.properties and maven.xml no longer exists, so this is defined in the pom.xml as follows:
org.apache.maven.plugins maven-clover-plugin ${path}/clover-xebia.license pre-site instrumentNote that there is a <configuration> tag, where you can define the necessary config for the plugin you use. Check the plugin documentation for further information, see maven.apache.org/plugins/ or https://mojo.codehaus.org/. The <executions> tag contains information about when this plugin should be executed. Each execution defines its phases, when should it be executed, and the goals it needs to execute. For more information about phases check introduction-to-the-lifecycle. The above configuration makes sure that clover will instrument (compile with clover) all sources and create a fresh clover database. In our projects we also have dependencies that are not available from the maven repository, like the sjsxp-1.0.jar. We have an internal repository for these kind of jars. To install jars and generate the pom.xml for these kind of jars you can do the following (thanks to this execellent blog): Make sure you have generated a private key and public key and have something like pageant running. Then add the following fragment to your settings.xml file:
... ... ssh-xebia-repo username /path/to/ppkfile/file.ppk /path/to/plink.exe /path/to/pscp.exeI used putty tools for this and it worked fine (after Maarten helped me out). Then execute the following command on the command line (note that the value of the [xml][/xml] attribute and the -DrepositoryId are the same):
mvn deploy:deploy-file -DgroupId=sjsxp -DartifactId=sjsxp -Dversion=1.0 -Durl=scpexe://url/path/to/repo -DrepositoryId=ssh-xebia-repo -DpomFile=pom.xml -Dfile=sjsxp-1.0.jar
Now in order to download artifacts from you internal repository you can define your repository in your pom.xml as follows:... xebia-repo Internal Xebia Repository https://url.repo.com/When you enabled authentication you have to define your user name and password in the settings.xml as follows (note that the value of the <id> attribute are the same):
... xebia-repo username passwordWe can now test, run site and deploy artifacts to a remote repository. Now let’s create the WAR. This is fairly easy with maven 2. Just add the following to your pom.xml
.... war ... ... org.apache.maven.plugins maven-war-plugin name-war src/webThe <packaging> attribute indicates that this project’s artifact is a WAR. Then you can add the maven-war-plugin and customize the default configuration. Then for example run
mvn package
, and the WAR is created.
When I created the WAR I noticed that the jta-1.0.1B.jar was included in the WAR. This is typically provided by the JEE (alias J2EE) server so I don’t want to include it in my WAR. As it turns out Hibernate has declared it as a dependency with the default (compile) scope (here is more information about scopes and dependencies) and hence it’s in my WAR. To not have it in my WAR I have to explicitly put in the dependency in my pom.xml with scope set too provided:javax.transaction jta 1.0.1B providedThis way it’s available during compilation but not put in my WAR. Our WAR runs on a weblogic server (8.1 SP4) and with maven 1.x we deployed it via the weblogic plugins. As it turns out this plugin is also available for maven 2. Here’s how you define it in your pom.xml:
... ... org.codehaus.mojo weblogic-maven-plugin 2.8.0-SNAPSHOT localhost 7001 http ${weblogic.userId} ${weblogic.password} false false false false ${weblogic.serverName}Because the userId and password can differ from installations this can be externalized in the settings.xml as follows:
weblogicConfig weblogic weblogic dev weblogicConfigThis goes for all properties you want to externalize, you have to create a <profile> and activate it in the <activeProfiles> section, there are other ways to activate it but that’s not relevant for now.Run [code]mvn weblogic:deploy[/code] and the application is deployed. Finally we are done! I you are planning to migrate take note of the following:
[WARNING] While downloading servletapi:servletapi:2.3 This artifact has been relocated to javax.servlet:servlet-api:2
. If you see this, just change the groupId and artifactId if necessary to the new location (the format of the message is: groupId:artifactId:version).