Main Tutorials

Integrate Maven with Eclipse via External Tool Configuration

During Eclipse development, it’s not practical to go outside of the Eclipse’s environment and execute Maven command in external console.

In this article, we show you how to integrate Maven command with Eclipse IDE, via Eclipse’s “External Tool Configuration“. Normally, this external tool is used to run external command within Eclipse environment, and it works prefectly with Maven command.

1. Configure “External Tool Configuration”

In Eclipse , menu bar, select “Run” –> “External Tool” –> “External Tool Configuration“. Create a new “program”, and link it to your Maven run command (mvn.bat in Windows), select the working project to run with Maven, and defined your Maven arguments, like “clean“, “clean package” , “test“, “install” and etc.

See following figure :

Integrate Maven with Eclipse

2. Run Maven in Eclipse

To run your new “External Tool Configuration“, select “Run” –> “External Tool” –> “tool name defined by you“. It will execute the Maven command and output the result in the Eclipse console view.

run maven command in eclipse
m2eclipse
Alternatively, you can install “m2eclipse Eclipse plugin“, which provides complete Maven integration for Eclipse IDE.

But, i do not like the plugin, because, Maven syntax comes with complete XSD support, and “External Tool Configuration” is work pretty well for me, just do not see any obvious benefits of installing this m2eclipse plugin.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
8 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jose Ayerdis
11 years ago

Still It is tedious to be clicking over and over the External Tool> maven test | clean

No even m2eclipse has support for running maven quickly (whats up with that??)

Fandi
11 years ago

Hy, Mkyong. can you show all configuration with external tools. ?
Thank you.

Fandy Akhmad
11 years ago
Reply to  mkyong

I think i just need configuration for create project like Java project, Web project, convert it to Eclipse
Because i try use maven command : mvn archetype:create it spent more times.

Thank you

amitav
9 years ago

[INFO] Scanning for projects…
[WARNING] The POM for org.apache.tomcat.maven:tomcat7-compiler-plugin:jar:7 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat7-compiler-plugin:7: Plugin org.apache.tomcat.maven:tomcat7-compiler-plugin:7 or one of its dependencies could not be resolved: Failure to find org.apache.tomcat.maven:tomcat7-compiler-plugin:jar:7 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ————————————————————————
[INFO] Building onLineExam 0.0.1-SNAPSHOT
[INFO] ————————————————————————
[WARNING] The POM for org.apache.tomcat.maven:tomcat7-compiler-plugin:jar:7 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat7-compiler-plugin:7: Plugin org.apache.tomcat.maven:tomcat7-compiler-plugin:7 or one of its dependencies could not be resolved: Failure to find org.apache.tomcat.maven:tomcat7-compiler-plugin:jar:7 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) @ onLineExam >>>
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ onLineExam —
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:OnlineExamProjectonLineExamsrcmainresources
[INFO]
[INFO] — maven-compiler-plugin:2.5.1:compile (default-compile) @ onLineExam —
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to E:OnlineExamProjectonLineExamtargetclasses
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 3.039 s
[INFO] Finished at: 2015-03-14T11:46:19+05:30
[INFO] Final Memory: 9M/112M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project onLineExam: Fatal error compiling: tools.jar not found: C:Program FilesJavajre1.8.0_25..libtools.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I’m running my project through eclipse.
need a solution?please help

Gubs
11 years ago

Hi Mkyong,

What’s the content available in .bat file ? Because i want to do the same for linux machine.

Gubs

Gubs
11 years ago
Reply to  Gubs

Hi Mkyong,

I installed maven in windows box also and found mvn.bat file is available in maven/bin directory. I will find the same in linux

Thanks

Gubs