3

I've been developing in Eclipse and every now and then I come across having to add JARs to WEB-INF\lib. My question is why sometimes I need to add them to the build path and sometimes I can just dump them in there.

dbyrne
  • 59,111
  • 13
  • 86
  • 103
Mauro
  • 589
  • 5
  • 15

3 Answers3

8

If you need them at compile time, they need to be in the build path. If you only need them at runtime, adding them to WEB-INF\lib is sufficient.

dbyrne
  • 59,111
  • 13
  • 86
  • 103
  • i knew it would be something simple like that. thanks a bunch! – Mauro Feb 22 '11 at 20:47
  • I don't think this is the correct answer. Please see my answer. – nanda Feb 22 '11 at 21:00
  • Depending on your project facets and Eclipse configuration, jars placed in the WEB-INF/lib directory may or may not be automatically added to the build path. However, that doesn't change the truthfulness of my answer? – dbyrne Feb 22 '11 at 21:06
  • I use Eclipse with Maven, and each dependency has an associated scope (compile, runtime, provided, test, etc.) – dbyrne Feb 22 '11 at 21:08
  • nanda, i don't have a problem with my configuration. it is a FACT that i have to add jars to the buildpath at times or just leave them in WEB-INF\lib. there is no problem there. i just wanted to know why, as correctly explained by dbyrne. your answer doesn't tell me why and tells me there is a problem where there is not. – Mauro Feb 22 '11 at 21:24
1

They need to be in the build path if any of your code explicitly references a Class in the jar. Sometimes jars you include reference these other jars that you don't explicity reference. Those jars do not have to be in your build path but they do need to be in your WEB-INF/lib directory.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
0

Well... I never encounter such problem with Eclipse. Let me ask you some questions:

  1. Are you using Eclipse JEE edition?
  2. Are you using Dynamic Web Project?

If you answer yes to both of them then you should get the jar on the build path automatically once you drop the jars in the WEB-INF\lib (maybe you need to refresh the project in Eclipse as well). Dynamic Web Project will automatically add all jars in the directory to the build path of the project.

If you still get problem then I think there is a problem with your Eclipse or your configuration.

From here (http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.wst.webtools.doc.user/topics/ccwebprj.html):

/lib

The supporting JAR files that your Web application references. Any classes in .jar files placed in this directory will be available for your Web application

nanda
  • 24,458
  • 13
  • 71
  • 90