This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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
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
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?
Joined: Jun 03, 2000
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