Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

After much reading of examples online I created a WAR file with a web.xml containing:

<servlet> <description>This is a servlet host for the
transformer</description> <display-name>Transformer</display-name>
<servlet-name>transformer</servlet-name>
<servlet-class>com.pepsi.transformer.TransformerServlet</servlet-class>
<load-on-startup>1</load-on-startup> </servlet>

And then in my .java file I have:

package com.pepsi.transformer;
public class TransformerServlet extends HttpServlet {

Then I built my ant script to stuff the TransformerServlet.class file into the WEB-INF/classes part of the WAR file. I have inspected it afterwords and found the .class file was there exactly as intended.

So ... then why do I see this error when I try to hit the doGet from the browser?

00000099 annotation W com.ibm.ws.webcontainer.annotation.WASAnnotationHelper collectClasses SRVE8000W: Skipped class that failed to initialize for annotation scanning. java.lang.ClassNotFoundException: com.pepsi.transformer.TransformerServlet at jav.lang.ClassforNameImpl(Native Method) ...

Did I overspecify the package? Should the classes folder contain un-compiled .java files? Does it need an init method? Does something else on the server need to know about this class file?

When you say you put TransformerServlet.class into the WEB-INF/classes did you put it directly in that folder? i.e. is it WEB-INF/classes/TransformerServlet.class or is it WEB-INF/classes/com/pepsi/transformer/TransformerServlet.class – Alasdair Nov 16, 2018 at 1:01 I'd really suggest you to use any Java EE IDE, like Eclipse. It will create all that for you when you will create simple dynamic web project. Also unless required, it is much easier to use @WebServlet annotation instead of defining servlet in web.xml. Go to the developer.ibm.com/wasdev/downloads/… and follow instructions to download and configure Eclipse with WebSphere Liberty. – Gas Nov 16, 2018 at 13:52 @Alasdair: Looks like they were going into WEB-INF and not WEB-INF/classes. Should they go into separate directories for each token in the fully qualified package name? – micahhoover Nov 19, 2018 at 13:41 With Ant, you want to use the <war> task and its <classes> element to point at the root of the package hierarchy directory. – dbreaux Nov 20, 2018 at 20:01

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.