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,
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
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.
Related
I'm developing a web application in JBoss in Eclipse Luna using external jars. I have imported the jars clicking on Project => Properties => Build Path => Add External Jars. Because the web application will need to use those jars, i have placed them in the MyApp.war/WEB-INF/lib folder, so, when the webapp will be finished, i'm sure i can just export the .war folder and deploy it on another server.
1) The problem is that everytime i turn on my pc in the morning, the deployment process gives me a ClassNotFoundException. I see that the external jars are no longer in their place. As far as i know, i'm not using any plugin to manage dependencies (i'm a newbie on webapps)
EDIT:
2) what i do is unpack my zip containing the jars again in the lib folder. Strangely, if i unpack them in a subfolder (for example, i place the jars in lib/httpcomponents/lib) JBoss cannot find the jars. What's the reason?
Try to inserting the external jar files in to jboss server lib directory (jboss\server\default\lib)
I have a very "basic" question regarding Java web application development (servlet). What is the difference between putting a jar file in WEB-INF/lib and putting it in Java Build Path/Library/External Jar?
Java Build Path/Library/External Jar is only managed by eclipse so if you build war and if your builder (or if you build externally) doesn't copy over these jars to WEB-INF/lib then you would loose them at runtime
also when you share that code with other developers, or if you use other IDE it will not help
better to use some standard and mature dependency manager / build tool like maven than copying over library to WEB-INF/lib manually
I have a java web application name webapp,when I export it to a war,the source codes will be compiled to the WEB-INF/classes.
Now I want these classed be compressed to a jar,and put into the WEB-INF/lib.
I have tried this:
create a new java project named webapp_jar.
Copy all the source codes under the webapp/src to the webapp_jar/src,configurate the build path to make the project work.
Add the webapp_jar reference to webapp project.
However ,when I run the webapp,it seems that the classes defined at webapp_jar can not be found.
Is this possible?
BTW,I use the eclipse ee ide.
have you try ant https://ant.apache.org/ ?
you could make a jar and copy it to folder you want and build the war after.
But , if I anderstand, you would package all the app to a jar ?
I think your webapp can't work without a servlet or two ...
This is really easy to do with maven by creating two subject projects, one to build the war, and the other as a jar project and then use the jar project as a dependency on your war project which would put the jar inside the lib directory when packaging the war.
No I use the Web Deployment Assembly settings in eclipse. I worked.
You can find details here.
When I was working with java spring hibernate struts2 eclipse project. I used buildpath-> addjar option to add jars from a folder inside the workspace. Even if the class is available it shows class not found exception.
If i put those jar files in web-inf/lib folder everything works.. Should i keep those files in the lib itself? Can i just include those jars in a seperate folder and add jar using eclipse configure build path??
what is the problem ? please help me... thanks in advance...
If you're using a standard Eclipse Dynamic web project, best way to go is to put all your Jars in the WEB-INF\lib folder. This will automatically add them to your build path and also include them in your WAR when you export it.
If you still want to use the Build Path > Add Jar option on the project, and want your Jars to also be included in your WAR, you have to go to the Project Properties > Deployment Assembly configuration and include them there. Of course this is double the work for every Jar.
When i created the dynamic web project, i will have 2 folders with name Libraries and lib. So during the project i added .jar files as follows
Build Path --> Configure Build Path--> Libraries (tab) --> Add external JAR's -- > OK
When i do this, it will add files to Libraries, However i would like to add .jar files to lib folder.
I tried copying all .jar files from Libraries to lib, but it says
Copied .jar files directly to lib folder in directory structure, but i doesn't display in eclipse.
I would appreciate your suggestions and inputs.
Copy jars into WEB-INF/lib directory by copying files themselves (not from Libraries in eclipse view) and hit refresh from eclipse, they will appear in the Web App Libraries
P.S: It is almost always better to use a build tool like maven/ant to manage dependencies
Open the lib folder in the file browser and paste all the copied
jars.
Refresh the lib folder in the