Ever need to connect to or login to a web site through a java application? Java offers some classes for handling http traffic in the java.net package. However, writing usable code using these classes takes a lot of lines of code, a lot of time, a lot of beer, and usually ends up in code that is less functional that you would like. How do we get around all this pain and still get a lot of beer? Here is the solution:
Jakarata Commons HttpClienthttp://hc.apache.org/httpclient-3.x/
HttpClient provides relatively easy to use classes for handeling Http communications. Simply download the tarball from the httpclient web site and you can be up and running in a matter of minutes. One way to go about this would be to put the java archive of all of the httpclient classes into your classpath. This can be placed into a location that is already recognized in the system wide $CLASSPATH or you can include the java archive file in the compile time classpath of your application.
An easy way to do this using Netbeans is to create a new java class library. In the projects tab on the left side of Netbeans the project should be listed. Right click on the project name and select Properties. Select Libraries. Select the tab Compile. Click Add Jar/Folder and browse for and select the commons java archive file. Finally, import any Package+Classes that your classes may need to call.
The HttpClient web site provides some excellent tutorials, sample code, and documentation to help an intermediate level Java programmer get well on their way to establishing many connections throughout the interwebs! Have fun.