Z T
Z T

Reputation: 570

Eclipse projects vs build path

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,

Upvotes: 0

Views: 173

Answers (2)

vkg
vkg

Reputation: 1869

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.

Upvotes: 1

Oleg Gryb
Oleg Gryb

Reputation: 5259

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

Upvotes: 3

Related Questions