• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to useCOM objects in Servlets(Tomcat 5.0.19)

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have a big problem.
I got t expain to u in detail.I have installed
tomcat 5.0.19 in windows xp.
I have set the classpath as follows:
C:\Documents and Settings\madhan\My Documents\servlets
C:\Tomcat\jakarta-tomcat-5.0.19\common\lib\servlet-api.jar
C:\Tomcat\jakarta-tomcat-5.0.19\common\lib\jsp-api.jar
catalina_home=c:\tomcat\jakarta-tomcat
path = c:\j2sdk1.4.2_04\bin;c:\tomcat\jakarta-tomcat\bin;%path%
Java_home=c:\j2sdk1.4.2_04
Iam able to run a simple servlet in "http://localhost:8080/servlet/Hello"
I have used "bridge2java" software to convert a
Visual Basic dll(trimSDK.dll) to a java dll
(bridge2java.dll)which contains the converted
java classes(COM objects).
Now i have these java classes(COM objects)
in c:\IBM\bridge2java
I can run a code using some classes
from it in c:\IBM\bridge2java
and it works fine.
c:\IBM\bridge2java\javac trim.java
c:\IBM\bridge2java\java trim
But when i include it in servlet it doesnt
run and i get an error like this:
Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/trim
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:435)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause
java.lang.NoClassDefFoundError: trimIBM/IDatabase
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:1610)
java.lang.Class.getConstructor0(Class.java:1922)
java.lang.Class.newInstance0(Class.java:278)
java.lang.Class.newInstance(Class.java:261)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:416)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
The code i used is:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.*;
import trimIBM.*;
/** Simple servlet used to test server.
* <P>
* Taken from Core Servlets and JavaServer Pages 2nd Edition
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2003 Marty Hall; may be freely used or adapted.
*/
public class trim extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
com.ibm.bridge2java.OleEnvironment.Initialize();
IDatabase d = (IDatabase) new Database();
d.set_Id("11");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>"+d.get_Name()+"</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>"+d.get_Name()+"</H1>\n" +
"</BODY></HTML>");
}
}

please do reply me with the solution of how to
use COM objects in tom cat servlet...
Regards
Madhan
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Madhan,
I think the problem is related to Tomcat not finding the class files that are in the trimIBM.*; package.
Hence the error: java.lang.NoClassDefFoundError: trimIBM/IDatabase
I assume IDatabase is one of the "converted" COM classes and is in your c:\IBM\bridge2java\trimIBM

When Tomcat starts it looks first starts up it loads the classes (and jars) in your
A. $JRE_install/lib (this may be implied)
B. $Catalina_home/common/lib
C. $Catalina_home/shared/lib
D. /WEB-INF/classes and /WEB-INF/lib
I would have also suggested to place them in the classpath but a bartender mentioned that Tomcat does not use the system classpath, so it would not help this situation. I guess that is only for when compiling.
So to get to the possible solution:
What you probably will have to do is copy all of the files in trimIBM and save them in your /WEB-INF/classes/trimIBM or JAR them and place them in the /WEB-INF/lib of your webapp.

I hope this helps...
reply
    Bookmark Topic Watch Topic
  • New Topic