Accessing external jar from servlet

From: Larry Coon (lmcoon_at_nospam_cox.net)
Date: 12/28/04

  • Next message: Java Lover: "Re: Accessing external jar from servlet"
    Date: Mon, 27 Dec 2004 22:08:54 -0800
    
    

    I'm trying to learn servlets, and am stuck getting the servlet
    to use JDBC (specifically, Sybase's JConnect), which I think is
    due to my not understanding how to provide the servlet with
    access to the JDBC's jar file. I'd like to provide a small,
    self-contained example, but I'm not sure that's possible here,
    so let me just describe what I'm trying to do.

    First, note the following:
      -- I can get basic servlets running (with Tomcat) just fine.
      -- I can use JDBC just fine with my Java applications.

    Where I'm stumped is with this concept: My jdbc classes are in
    C:\Java\jConnect-5_5\classes\jconn2.jar

    >From an _application_ I just import the right classes:
      import com.sybase.jdbc2.jdbc.*;

    and do the usual Class.forName to load the driver:
      Class.forName("com.sybase.jdbc2.jdbc.SybDriver");

    and then I can tell the jvm where the jar file is:
    java -cp .;C:\Java\jConnect-5_5\classes\jconn2.jar mypackage.MyApp

    and all is well. But with a servlet, how do I provide that
    connection between the Java code and the jar file? When I invoke
    my servlet, Tomcat's log contains the following:
    java.lang.ClassNotFoundException: com.sybase.jdbc2.jdbc.SybDriver
    (followed by a full stack trace) afterward. The stack trace
    indicates it choked during the Class.forName(), i.e., when trying
    to load the driver.

    The obvious thing (to me) seemed to be the CLASSPATH env variable,
    but pointing CLASSPATH to the jar file didn't make any difference.
    I tried checking all the docs I could find, but didn't find anything
    that helped me (which I assume is a case of information overload on
    my part rather than the information not being out there). Any
    pointers would be appreciated.

    Thanks.


  • Next message: Java Lover: "Re: Accessing external jar from servlet"

    Relevant Pages

    • Re: Best practice for initializing JDBC connection in Servlets.
      ... > access the servlet simultaneously? ... initialize the JDBC driver in initand manage connections in doGet. ...
      (comp.lang.java.programmer)
    • Re: Exception in thread "main" java.lang.NoClassDefFoundError:
      ... Make sure that the excel api jar file is in the classpath. ... > Alright, I am new to Java, and I am having some major issues with it. ... > I am writing a servlet that will tinker with excel files, ...
      (comp.lang.java.programmer)
    • Re: CLOS and C++
      ... so why is subclassing Servlet to make a new kind of servlet not ... > find methods which would be true for all lab instruments, ... All I'm saying is that Java programmers do reuse code ... But if you don't like Servlets, take JDBC drivers. ...
      (comp.lang.lisp)
    • Re: Servlets, JDBC Oracle Connection Mode
      ... > I'm actually new to Java and JDBC, ... running Tomcat is not the same as Database Server ... You then need a signed applet. ... I'd create a servlet as ...
      (comp.lang.java.databases)
    • Re: Building a Business Application
      ... >from the presentation layer? ... you might consider a report generator. ... Another approach would be to use a servlet that talk to JDBC, ...
      (comp.lang.java.databases)