Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

issues with tomcat and loading external libraries

Options
  • 27-10-2006 8:59am
    #1
    Closed Accounts Posts: 85 ✭✭


    Hi,

    I'm using redhat core 4 x86
    tomcat 5.0

    I'm new to tomcat and I'm trying to write a screenscraping prototype servlet
    using the jakarta commons-httpclient.jar external library. I've based the
    directory structure of the application on the demo given here :

    http://tomcat.apache.org/tomcat-5.0-doc/appdev/processes.html

    so it looks something like :
    web
    build
    build.properties
    build.xml
    docs
    src
          scraper
          first.java
    web
          index.jsp
          WEB-INF
               lib
               web.xml
    


    ant compiles the whole thing into the build directory. If the first.java file has
    no references to external libraries the whole thing works fine.

    The problems start when I try to get it to reference classes in the
    commons-httpclient.jar. I'd prefer for this library to only be accessible to this
    webapp, so I copied it into the web/WEB-INF/lib/ directory along with its
    dependencies - some logging stuff and a decoding jar .......... - but ant does
    not see the files in this location, and when I try to compile it using ant, will
    spit out compiler messages relating to all lines of code referencing the
    external lib.

    My impression from research was that {app_root}/WEB-INF/lib was the
    directory where external libs went ;
    is there another step after copying the files there to register them with the
    context classpath ?

    Also - another thing, if I copy the external libraries to the system classpath at
    /usr/share/tomcat5/common/lib/ The app will compile, but if I try and access
    it through the browser it doesn't work and the tomcat logs give me this :

    2006-10-27 14:56:49 StandardWrapperValve[jsp]: Servlet.service() for 
    servlet jsp threw exception java.lang.NoClassDefFoundError: while resolving 
    class: org.apache.commons.httpclient.URI
    .
    .
    .
    .
    .
    .
    .
    Caused by: java.lang.ClassNotFoundException: 
    org.apache.commons.codec.DecoderException not found in 
    gnu.gcj.runtime.SystemClassLoader{urls=[file:/usr/lib/jvm/java/lib/tools.jar,
    file:/usr/share/tomcat5/bin/bootstrap.jar,
    file:/usr/share/java/commons-logging-api.jar,
    file:/usr/share/java/mx4j/mx4j.jar], 
    parent= gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
    
    

    The decoder is a dependency of the httpclient and its jarfile is sitting right
    beside the httpclient one.

    Does anyone anyone have any ideas. Any help would be greatly appreciated.
    I've been farting around with this trying to get it to work for far too long .....

    Thanks

    Colm


Comments

  • Registered Users Posts: 1,996 ✭✭✭lynchie


    You are correct in that all jar files e.g. commons-httpclient-xxx.jar etc should be in WEB-INF/lib. Tomcat should pick them up from there.

    What is interesting is the stacktrace. Are you using the gnu java compiler and not Sun's? Try using plain sun compiler and jre. According to the stacktrace, the webapps/<your_app>/WEB-INF/lib folder is not on the classpath which is strange.


  • Registered Users Posts: 5,618 ✭✭✭Civilian_Target


    In your WEB-INF folder create a file called MANIFEST.MF and add the lines:
    Manifest-Version: 1.0
    Class-Path:  WEB-INF/lib/nameofjar.jar
    

    I usually just put my JARs in the root directory so that I don't specify any path as an argument, just the name of the JAR. (But I also use Websphere instead of Tomcat. Go figure)


  • Closed Accounts Posts: 85 ✭✭protos


    thanks for the replies.

    Yes - I'm using the gnu java compiler - I'll give the sun jdk a go and see if that makes a difference.

    I have to say - the hardest thing with getting servlets / jsp working is not the actual programming but the configuration - its a real pain !!


  • Registered Users Posts: 5,618 ✭✭✭Civilian_Target


    protos wrote:
    I have to say - the hardest thing with getting servlets / jsp working is not the actual programming but the configuration - its a real pain !!
    If you're just starting out, I absolutely agree! The programming's familiar stuff but the configuration requires a good grasp of the concepts before you start, and most books don't explain these until later on.

    [EDIT]If Tomcat is pissing you off - try WAS Community Edition - you might find it easier[/EDIT]


Advertisement