0

I am building a library which wraps some code around spymemcached client. This is called CacheClient. This is s simple Java project. I put the spymemcached.jar into its lib folder.

Here is how it looks like, also you can see the build path settings:

Library: CacheClient Project: cacheclient.jar

  • lib
    • spymemcached.jar

Java Build Path / Libraries Tab: spymemcached.jar - CacheClient/lib/spymemcached.jar

What I am doing is I am building a simple java web project which is using this library.

WebApp: ServiceWebApp Project: servicewebapp.war

  • WebContent
    • WEB-INF
      • lib
        • EMPTY

Java Build Path / Projects Tab: CacheClient

So, my Webapp's build path is set to using the CacheClient project. I copied the cacheclient.jar into tomcat's lib directory and deployed the ServiceWebApp.

When I run the web app, it fails as it says my CacheClient code is looking for the spymemcached classes (ClassNotFoundException).

I could solve this by putting spymemcached.jar into tomcat's lib directory but it would be great if there will be an other solution.

Any suggestion appreciated.

Thanks,

Z T
  • 543
  • 1
  • 7
  • 26

2 Answers2

3

The simplest way of making the lib available in your web app would be to put the lib's jar to your WEB-INF/lib directory.

If you don't want to do it manually, check this link about how this can be automated: Adding 3rd party jars to WEB-INF/lib automatically using Eclipse/Tomcat

Community
  • 1
  • 1
Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
  • OK this was the solution. I put the cacheclient.jar and also the spymemcached.jar into the web app's WEB-INF/lib dir. However the spymemcached.jar is also in the cacheclient.jar's lib dir. As I can see to reference a class from a jar inside a library is not natively supported, so One-Jar or any other packaging is needed. – Z T May 23 '14 at 19:54
1

In your case cacheclient.jar has a dependency on spymemcached.jar. But when your cacheclient.jar is built it's not packaged with spymemcached.jar. So just copying cacheclient.jar in tomcat/lib folder is not enough. In first place it's not a good practice to copy jar files in tomcat lib folder.

What you can do is copy both your jars in servicewebapp.war > WenContent>WEB-INF>lib that should work.

vkg
  • 1,839
  • 14
  • 15