Skip navigation

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.

Create New Maven Project

Create New Maven Project

Then you will have the new Maven project in your package explorer. New project will consists of JUnit library by default.

Maven Project in Package Explorer

Maven Project in Package Explorer

It will also comes with App.java class by default. I will use this java class for the demo.

Standard App.java

Standard App.java

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.

Added Log and LogFactory object.

Added Log and LogFactory object.

Next, I highlighted the ‘Log’ object and I pressed Ctrl+1 to pop out the context menu. Then, choose ‘Search dependency for Log’ option.

Search for dependency from context menu

Search for dependency from context menu

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.

Choose specific library

Choose specific library

Automatically, commons-logging library will be in my project’s classpath.

Commons-logging jar file is added

Commons-logging jar file is added

Log class also will be automatically imported into App.java class.

Log object is imported

Log object is imported

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.

Import LogFactory class.

Import LogFactory class.

My pom file is also updated automatically.

POM updated

POM updated

Isn’t this a great feature? No more searching and downloading the libraries manually from the web. Hellooo productivitayyyy.

2 Comments

  1. 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.*.

  2. 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

  1. By Breves « Ubuntu Life on 10 Dec 2008 at 9:30 pm

    […] 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 […]

Leave a comment