File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes How to useCOM objects in  Servlets(Tomcat 5.0.19) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to useCOM objects in  Servlets(Tomcat 5.0.19)" Watch "How to useCOM objects in  Servlets(Tomcat 5.0.19)" New topic
Author

How to useCOM objects in Servlets(Tomcat 5.0.19)

Madhan Kumar
Greenhorn

Joined: Apr 03, 2004
Posts: 9
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
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
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...


A. Valentin
 
Don't get me started about those stupid light bulbs.
 
subject: How to useCOM objects in Servlets(Tomcat 5.0.19)