File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Simple MAVEN questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Simple MAVEN questions" Watch "Simple MAVEN questions" New topic
Author

Simple MAVEN questions

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Just starting using Maven after about ten years of ANT!

Some questions:

1. In ANT I could very easily write a target to move some files around my system and call this without calling anything else?
How do I do this in MAVEN
2. In ANT I could very easily crate a target to call a PMD task to run PMD on my source code - how do I do this in maven?
3.for a plugin what is the difference between an execution,a goal and a phase?
4. Is it possible to debug a POM.xml?
5. What is the nexus indexer?
6. Is it possible to configure what port maven uses when it searches the global repository?

Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2448
    
  28

Generally most things in maven are done using plugins and there are plugins for just about anything that can be found by just googling for it. I'll attempt to answer through.

1) There is a plugin for that. You can use the the maven resources plugin. If you don't specify a phase in the execution tag, then it won't execute as part of your normal build. You can execute it using mvn resource:copy-resources
2) There is a plugin for that. http://maven.apache.org/plugins/maven-pmd-plugin/
3) Think of a goal as a method on the plugin, and think of execution as parameters to the method. A execution may or may not be tied to a phase. Maven goes through phases when it does the build, and for each phase it executes the executions that are tied to the phase
4) Not that I know of. However, maven logs plenty, and plenty more if you turn on verbose. I have been using maven for close to 2 years now, and haven;t found the need to debug a pom.xml
5) DOn't know how much you know about maven repositories. But, simply put, nexus is an implementation of a maven repository. Nexus is not the only one. There is Artifactory too. It is popular and reccomended because it does lazy caching of other maven repos. The way it works in maven is that you never checkin your dependent libraries in your source control. What you do is in your pom, you list out the libraries that your project needs. Maven downloads the jars from the maven repo. Now, if these libraries need libraries themselves, maven downloads them too. This prevents you from going into Jar Hell, where you have all these unrelated libraries checking into your SVN that you have no idea what they are being used for. The disadvantage of this is that since lot of people started using maven, the load on maven repo became a problem. So, they reccomended that people install their own maven repo mirror in their local networks, so they don't have to hit the central repo everytime. The problem is that maintaining the mirror is cumbersome. So, here comes Nexus indexer that makes it easy for you to mirror. You install Nexus in your local network, and configure your POM to get the libraries from your Nexus. If Nexus has it, it gives it to you, otherwise it gets it from central maven repo and puts it in it's own repo. Next time you need the library, Nexus will provide it from it's local storage instead of hitting the central repo

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Thanks so much for your answer. I'm a little bit confused about defined the PMD plugin.

My understanding is I can define it in <build> or <reporting>? Which makes more sense?

Also how do I call it without calling other life cycle "phases"? My understanding is with maven say when you call say "test" it *always* calls previous life cycle phases?

Is it possible to define the PMD plugin in my pom.xml so that it can be run without anything else running?

Thanks.

Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2448
    
  28

Look at the documentation on the plugin in my link above. Read the goals and usage. It has examples on how to call the goals directly and how to bind it to a phase
Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Jayesh A Lalwani wrote:Look at the documentation on the plugin in my link above. Read the goals and usage. It has examples on how to call the goals directly and how to bind it to a phase


In the first link, copy-resource goal is configured to run during the phase validate for the mavane-resources-plugin.
How do I know what phases a plugin has?


Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Some update, manged to get something to work.

I added the following into <build>...<plugins>.../<plugins> </build>



PMD has four goals: pmd, cpd, pmd:check, pmd:cpcheck

To execute the first goal pmd, I did:
>mvn pmd:pmd

This outputs pmd results to:

%project-home%\target\site


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple MAVEN questions