When I run mvn compile from command line, it builds using pom.xml. But when I try to run it within eclipse (by using m2eclipse plugin), when I right click on the pom.xml and run as maven build, it asks for a goal. I am new to maven and want to run it through eclipse. So why doesn't it ask for anything when running from command line? Is there a default goal?
Yes, there is a default goal, but what it is depends on the project, and can be explicitly defined.
See the BaseBuild Element Set (the default goal is
install) as well as the rest of that page for further information. IIRC you can define a default goal for m2eclipse, although I haven't used it in some time.
There's also a setting to define a goal to be run when a source directory is updated: