HTTPClient on Tomcat - java

I really apologize if this is a silly question.
I have a tomcat server running on a unix machine. I want to use the HTTPClient library. Does it come pre-bundled with tomcat or do you need to install it?
If people say to just add it to your class path. Should I download the source or the binary from here:
http://hc.apache.org/downloads.cgi
Once downloaded is there a way to auto install it using a .tar.gz as I think I have done this in the past. If not is it just a case of putting the folder on the drive and adding it to the classpath?
TIA

Each web application is supposed to package its own dependencies inside the deployable WAR file. It is an ill-advised practice to extend Tomcat's global library with any library an application might need.
On the WAR building front, the common practice you should stick to is not to manage dependencies on your own; it quickly turns into a nightmare. Configure your project with Maven , which will both manage the dependencies and build the WAR for you.

Just look for httpclient....jar file in the Tomcat directory. If there is none there, then put it inside the lib directory :)
You should download the appropriate jar file. It contains portable library code. Once placed in the classpath, Tomcat will find it. Tomcat directory has a lib subdirectory. This is global classpath part for all web applications.

Related

How are java dependencies deployed on server machine

Did a lot of research but could not find a proper answer. My question is simple - I am building an executable jar file which has few external dependencies like spring etc. Now I want to deploy my executable jar file to server machine. Is there a easy and safe way of achieving it? Few options I am aware of:
Build an uber jar with all the dependencies bundled along with application code and deploy it
Deploy the source code executable jar and then manually add all the dependency jar files to the class path
Is there any other better way? Any tools which can help here? How are dependency jar upgrades handled? - Are they manually replaced on server machine?
If you 'just' have an executable jar and some other jar files as dependencies (this is the most common case actually), you can follow best practice standards and create a zip file containing them all. Check how various open source projects offer their stuff for download.
If you use some framework that might also guide you about deployment. As an example, the servlet specification tells you how to create that zip file in chapter 10.
If you want another way more compliant to the OS package manager, you could take a look at JPackage. It also bundles a Java Runtime so you have tight control not just about the jar dependencies but also the runtime.

How to put additional server libs to Tomcat(JBossEWS) on Openshift?

I have a Tomcat/JBossEWS application on Openshift and would need to put some shared jars into lib directory - jbossews/lib. However this directory does not have permission to do this.
I do not use Git and deploy compiled war.
Where can I put shared libraries and how?
You need to use GIT for this, as far as I know, there is no way around it.
Make a lib directory in your application and place your files there, use git to commit them. The procedure is described here: openshift - tomcat dependencies
You can put your libs somewhere else, for example into app-root/data/lib, and then edit jbossews/conf/catalina.properties: append "${catalina.base}/../app-root/data/lib/*.jar" at the end of "common.loader" property

eclipse tomcat: take the classpath from the project

I have a java web project in eclipse and want to define a tomcat server.
It seems that in the tomcat server I must define again my classpath. How can I tell tomcat to just use the classpath from my project (shouldn't this be obvious?).
Unfortunately my jars are scattered all around and it is an headache to add them one by one to my tomcat configuration and maintain this.
Here you go :
Run -> Run Configurations... -> Classpath
You don't have to tell tomcat to look for jars scattered all around the places. This can be easily taken care by eclipse. Configure your eclipse build path properly. Create Libraries (in eclipse) and group jar together. Try to export the war and check if eclipse is packaging all the required jars in WEB-INF/lib.
No, Tomcat and web apps have a pretty well-defined CLASSPATH. You shouldn't have to specify anything if you package your app properly:
All the packages and .class files in WEB-INF/classes are in CLASSPATH.
So are all the JARs in WEB-INF/lib
You should figure out how to put your JARs in the right place - that's WEB-INF/lib of your WAR file. Maybe Ant or Maven can help you.

Installing jar file to Tomcat web application

How do I install a 3rd party JAR file to my tomcat web application?
I have placed it in every folder I can think of, and am referencing it like:
import com.google.api.translate;
Is there a particular folder? I have tried WEB_INF/lib
If all apps on Tomcat need that JAR, the place to put it would be /lib if you're using Tomcat 6.x or higher and /server/lib if it's version 5.x or lower.
If only your app needs a 3rd party JAR, put it in WEB-INF/lib.
I hope you're packaging your app as a WAR file.
I have placed it in every folder I can think of
I'd recommend reading a bit more about Tomcat and CLASSPATH before you proceed.
import com.google.api.translate;
This doesn't look like proper Java to me. Shouldn't that be:
import com.google.api.translate.*;
What is the name of the JAR containing those classes? Where did you find it?
Looks like you want to use Google's translate API somehow.

Apache Ant + Ivy build of a web application which is deployed to a local Tomcat

I will use Apache Ant and Apache Ivy to build a web application which is deployed to a local Tomcat instance (during development). I have some questions:
I want to grab most of my dependencies from the Maven2 repositories which works fine, but for the servlet JAR I would like to use the one Tomcat provides. Is there a way to do that using Ivy? And what do you think about doing so?
I download the Ivy JAR using Ant to "auto install" it into ~/.ivy2/jar/ivy.jar and I have the Ivy cache at its default location ~/.ivy2/cache . I keep both of these locations outside the project directory on purpose. Good idea?
Do you have an example of how to use Ant for the build file, Ivy to resolve dependencies, compile a WAR file and deploy it to a local (at the moment) Tomcat installation? I'm looking for something to have as a best practice which I then can modify further.
I've used some examples on the Ivy web site and modified them. Is there anything I should change? The build file can be seen at http://pastebin.com/f7b34abc2 , as I had problems pasting XML code in here.
(Please notice that I'm not looking for the suggestion that I should use Maven2, even if the suggestion is well intended.)
At runtime tomcat will use it's own away as it's classloader will exclude any jar with javax.servlet.Servlet in it. If you really really must compile against it you will have to do it in the ant script, and either copy it or reference it in the compile classpath.
On the other stuff, downloading ivy on demand is a good idea as it will prevent checking the ivy jar into the project scm repo as I have done in the past, whether you download it to the project directory or the user home is a matter of personal preference. The ivy cache on the other hand should be shared with other projects so the user home directory is a good location.
Building the war file isn't any different once you have done ivy:retrieve as the jar files required will be local to the project, just use the ant war task to create the war as normal. This is one advantage to ivy, that once the jars are downloaded it has no more to do in the build and you can just use ant to compile and package your project.
Had a quick look at your build file, looks perfectly sane.
Hope this helps.

Categories