• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Where do I need to put a .jar file so Tomcat under Eclipse finds it?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is related to another issue https://coderanch.com/t/105180/vc/WTP but I thought I would rephrase the subject to make it clearer.

I'm running Eclipse with WTP and Tomcat. I have a JSP page that opens an http connection to another web server. I'm using Jakarta Common's httpclient library. I added the .jar to the project and I'm able to use the objects in the library without problems when composing the JSP. Autocomplete works ok and I don't get any errors.

But when I try to run the JSP on Tomcat inside Eclipse I get several errors like

org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:
Only a type can be imported. org.apache.commons.httpclient.HttpClient resolves to a package

Generated servlet error:
Only a type can be imported. org.apache.commons.httpclient.HttpConnection resolves to a package

I'm almost sure that I have to include the jar file somewhere for Tomcat to be able to use it when compiling the JSP but I'm not sure where. Can anyone help me with this?

Thanks
 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After several tries I found that if I copy the jar file manually to ${catalina.home}/common/lib it works. That�s a workaround, but I will try to keep the jar in another folder for ease of management.

I found that ${catalina.home}/common/lib is referenced in common.loader in Catalina.properties, but if I add the path where I want my jar to reside it does not work. Any other place where the path to my jar should be added.

Thanks
 
author & internet detective
Posts: 41988
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fernando,
Thanks for sharing the solution.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very poor decision. You should have made sure the jar was inside your project in a place where it could be found at runtime.
 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeroen

As I said, mine was a workaround but I'm still trying to get a better solution.

Very poor decision. You should have made sure the jar was inside your project in a place where it could be found at runtime.



It looks like you have one. Would you be kind enough to share it with us. At least a little more detail will help me, because adding the JAR to my projecty looked to me that was enough for having it available at runtime.

Thanks
 
Saloon Keeper
Posts: 28223
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Only a type can be imported. org.apache.commons.httpclient.HttpClient resolves to a package



This disturbs me. It implies that someone - either you or some version of the apache commons HttpClient system had defined classes in a package named. org.apache.commons.httpclient.HttpClient. Or, at least that there's a construct in a jar or war somewhere that has a directory structure that implies such a thing.

Using caps in a package name component is a Bad Thing. It's not enforced by the language, but since classnames should have caps in them, it helps people keep track of which was which.

Of course, this may just be Jasper getting confused because it can't find something, but it's quite possible that you have a bogus package in your path and you're pushing it out of sight by what you do.

Jasper will use the classes in your webapp's classpath to resolve compilation references. So the correct place to put your HttpClient jar is in the webapp's WEB-INF/lib directory.
 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim

There's not such package or directory. While researching this problem I found that it's a common problem to have Jasper to report that a class reference resolves to a package when it cannot find the requested class within the class path. I'm not sure if it was related to the fact of being used under Eclipse or not.
 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Larry at the eclipse.webtools newsgroup. This fixed my problem.


I finally found time to verify this. This occurs when you add a jar directly to the Java Build Path instead of adding it as a J2EE Module Dependency (via the project Properties page by the same name) or copying the jar to the project's WEB-INF/lib. Either of these approaches includes the jar in the webapp's WEB-INF/lib when the project is published to a server or exported as a war file. Adding the jar directly to the Java Build Path implies that the server will supply this jar via something like Tomcat's "shared/lib" feature. The errors are the result of not including the jar in the webapp, so the classes are not present and the imports in the JSP are assumed by default to be packages.

 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic