Traditionally, creating a new Java project is very cumbersome and time consuming, especially when you required a lot of external libraries. I might have to go to each library’s project website to search and download the jar file. Most probably I might just copied from previous project’s libraries.
Maven and Eclipse help me to avoid this mundane work. The feature of Maven with Eclipse I like to demo right now is the ‘Search for dependency from central repository’.
First, you need to do is create a Maven Project like below.
Then you will have the new Maven project in your package explorer. New project will consists of JUnit library by default.
It will also comes with App.java class by default. I will use this java class for the demo.
Let’s say I need to use commons-logging library, which is not yet included in the project’s classpath. I just typed in the code and of course I will get the errors as below.
Next, I highlighted the ‘Log’ object and I pressed Ctrl+1 to pop out the context menu. Then, choose ‘Search dependency for Log’ option.
I typed ‘*logging’ to search for the specific Log’s library. It will search the maven central repository based on the pattern. Then, I select Log class from commons-logging artifact.
Automatically, commons-logging library will be in my project’s classpath.
Log class also will be automatically imported into App.java class.
Since LogFactory class is from the same library, I just need to import the class by pressing Ctrl+Shift+O. This would solve all the problem and error.
My pom file is also updated automatically.
Isn’t this a great feature? No more searching and downloading the libraries manually from the web. Hellooo productivitayyyy.
2 Comments
I try to imported import org.apache.struts2.config.Result; in my source code but cannot found Result package in Maven repository.Last time,I add struts2-core,struts2-annotations.It’s cannot found Result package in org.apache.struts2.*.
Dear Mr..
I found this http://smellsthecoffee.blogspot.com/2007/10/insert-statement-with-reserved-word.html on your blog and it helped me a lot!
Thanks, and have fun programming.
One Trackback/Pingback
[…] Kidzui, extension para Firefox y navegador para niños * Una mirada a Elementary Desktop project * Maven en Eclipse * Tutoriales JavaFX * Beta 2 de Firefox 3.1 * Guia de comparacion de netbooks antes de comprar una […]