2

I begun this Spring MVC Step-By-Step Tutorial part 1 at 1.8 it says

"If you are using an IDE, you will want to configure your project's build path by adding the jars from the 'lib' directory. You will also want to add servlet-api.jar from your servlet container's 'lib' directory ('${appserver.lib}'). Adding these to your build path should successfully resolve all the import statements in the 'HelloController.java' file."

I add jars in the 'lib' folder but the issues does not solves. I could not figure out how to configure the build path. Can any one help. Thanks

AbdulAziz
  • 5,868
  • 14
  • 56
  • 77

1 Answers1

4

Right-click on your project root and select Build Path -> Configure Build Path.... Select the Libraries -tab and click Add JARs.... Navigate to your projects' lib-folder and select the .jar -files, then click Ok.

Edit: From the comment below:

can I define the library once and for every project I just mention the path

If you have multiple projects that use the same jar-archive or archives, you can define a User library for your Eclipse-installation: Select Window -> Preferences, then Java -> Build Path -> User Libraries. Click New, give a name to your user library and click Ok. Select the User library you just added, and click Add JARs..., navigate to the jar you want to add to the library and click Ok. Note that single User library can contain multiple jars (such as all needed Spring-jars, like core, webmvc, tx...), so you can keep repeating the Add JARs... -step.

When you want to use the defined user library in your project, go to the Libraries -tab in your projects' Build Path, and click Add Library, then select User Library and click Next. Now you can pick the library from your user libraries you've defined.

esaj
  • 15,875
  • 5
  • 38
  • 52
  • Thank you for your kind answer. yes it works. Is there any way doing this, because doing this (adding jars twice) is a bit confusing. I mean can I define the library once and for every project I just mention the path. How can I do this? – AbdulAziz Feb 11 '12 at 11:41
  • 1
    By using Maven (or another build tool) – Sean Patrick Floyd Feb 11 '12 at 11:57
  • @AbdulAziz: See my edited answer. Not sure what you mean by 'adding jars twice', Build Path does not copy the jar anywhere, it just tells the environment that your project needs the jar as a dependency. So it's just project configuration that tells the compiler etc. where to find the needed jars. Like Sean Patrick Floyd suggested, using maven is also a very good way to get away from all the hassle of the Build Path, personally I've been a maven user for the last 4 years or so, and never looked back. – esaj Feb 11 '12 at 11:58
  • @esaj Thank you for your very kind reply. I am new for Web applications. I didn't used maven and i am kind of afraid using it, so I preferred to add jars manually. Can you suggest easy way to use maven. – AbdulAziz Feb 11 '12 at 13:06
  • 1
    Easiest way is to install maven-plugin for Eclipse: http://eclipse.org/m2e/download/. I'd also suggest reading the documentation from http://maven.apache.org/index.html. http://www.eclipse.org/m2e/ has some video-tutorial about maven-usage, and there are probably loads of tutorials and examples to find with a little bit of googling. Good luck! – esaj Feb 11 '12 at 13:15
  • @esaj Thanks a lot. I am really grateful to you for your help. – AbdulAziz Feb 11 '12 at 23:25