Monday, November 4, 2013

Maven FAQs

Maven, as a build tool replacement for ANT, has been on my Radar for last few months now. Although, we as team are little late to adopt it. However, for late adopters, there is always an added advantage of availability of resources.
 
There are plenty of resources and books available online at the cost, it uses your network bandwidth. However, for a build tool, usually we go by learning only what we need to do and mostly, "learning by doing" approach. Hence, maintaining this FAQ of a some of the interesting find outs of Maven, while trying to learn it, following the reverse engineering way. 

Please Note: Many of us, including me, would agree that Maven is not just the build tool. But, it always wise to learn walking first, rather than learning how to run, isn't it? :)

What does it mean if the maven dependency is of type war?

http://maven.apache.org/plugins/maven-war-plugin/overlays.html

What is transitive dependency?


What does different dependency scopes mean?

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

How to test a webapp using Jetty?

http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html

How to force maven to update local maven repository?

http://stackoverflow.com/questions/15673431/how-to-force-maven-to-update-local-repo

How to enable compilation at a particular Java version, say JDK1.5?

By default, if you run the maven build from eclipse, it takes the build JDK version set up in the Eclipse's project environment. So, to enable the build at higher or lower JDK level,  add this to your plugin list, so that the correct version is being taken for java compiler:


<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>2.0.2</version>
 <configuration>
  <source>1.5</source>
  <target>1.5</target>
 </configuration>
</plugin> 
 

Eclipse fails to copy resources, results in error something like below:

org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the plugin manager executing goal 'org.apache.maven.plugins:maven-resources-plugin:2.2:resources': Mojo execution failed.

We faced this issue while running maven build from eclipse, after bit of goggling and connecting some dots, we realized that the default maven-resources-plugin version used by eclipse, which is by the way defined in some pom.xml somewhere in your eclipse installation folder, was 2.1. This is a bit buggy when it is used with certain eclipse variants. So, in order to resolve this problem, point it to a higher version plugin. To do this, add the maven-resources-plugin, a plugin entry in your <plugins> list of pom.xml, precisely, like this:


<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-resources-plugin</artifactId>
 <version>2.5</version>
</plugin>
 
In my case, pointing it to 2.5 resolved this issue.
 

Using Maven, compiling and Running a Java File, with main() method?

 
mvn compile exec:java -Dexec.mainClass="com.myapp.App"  

 
  

No comments:

Post a Comment

Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...