aspose file tools*
The moose likes Servlets and the fly likes Need help in using an external class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need help in using an external class" Watch "Need help in using an external class" New topic
Author

Need help in using an external class

Suvrat Joshi
Greenhorn

Joined: Aug 10, 2001
Posts: 11
I have a simple servlet and am trying to log some messages to a file (local directory) using this servlet. The LogFileWriter is a generic class that writes to a file and create the file if it doesnt exist. The servlet instantiates this class and uses it. I have tried numerous combinations (putting them in the same package with and without a package identifier, etc..) however, I have not been succesfull. The error I get is java.lang.NoClassDefFoundError: MyServlet/ServletCode/Servlets/LogFileWriterNew and a bunch of other errors.
How do i use an external class in a servlet?
IDE: Forte
Web Server: Tomcat
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Servlet classes are to be placed in the WEB-INF/classes/
folder of your application when using Tomcat App server.
Having said that, you should additionally ensure that you
follow the package structure under the classes folder.
Another way to do this esp. when it is an external file is
to get it in the form of a jar file and put the jar file
in WEB-INF/lib/ folder.
In your servlet, call the class with the proper package.
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Suvrat Joshi
Greenhorn

Joined: Aug 10, 2001
Posts: 11
Thanks!! This worked. The jar solution is not working, but I think there are some package related issues here. I think I am having some problems with packages in the IDE. Though unrelated, wonder if you can help me with the following problem with FORTE:

I have 2 classes in the same package. I DO NOT have the package qualifier for both the classes. Class 2 instantiates Class 1. Class 1 compiles fine. Class 2 gives an error saying cannot find Type in import statement -- hinting that it could not locate Class 1, when both are in the same package.
However, it works if I do the following.
Go to the Projects tab.
Add the 2 files, Class 1 and Class 2.
Do a build project. I get the compiled Class files for both the
Classes.
I go back to the FileSystems tab and try to compile the classes, they dont compile!! Lastly, if I hover my mouse on Class 1 or 2, I get the ballon "invalid Package Declaration"
How do I resolve this error?
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

I am not a FORTE gig...never worked with it.
I would first suspect the CLASSPATH....
You might want to ask in the IDE forum about
this.
regds.
- satya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help in using an external class