ServletException vs packages

Discussion in 'Java' started by googleRon, Feb 25, 2006.

  1. googleRon

    googleRon Guest

    Gentle(wo)men,

    I tried to invoke a simple servlet "Test1" which is (just for testing
    purposes) part of the package "myPackage" and its class-file is in
    C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes\myPackage

    I get from Tomcat the following error-report:

    exception:
    javax.servlet.ServletException: Error allocating a servlet instance

    root cause:
    java.lang.NoClassDefFoundError: Illegal name: myPackage/Test2

    Here are some things that I did in advance to let the invocation of the
    servlet works proper (as I presumed)

    The first line in Test1.java is:
    package myPackage;

    I copied the class file Test1.class (which compiled well) from the
    developing map to the map
    C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes\myPackage

    I put the line
    "C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes" in the
    environment variable ClassPath.

    I adapted/edit web.xml bij adding the following lines:

    <servlet>
    <servlet-name>Test1</servlet-name>
    <servlet-class>myPackage/Test2</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>Test1</servlet-name>
    <url-pattern>/Test1</url-pattern>
    </servlet-mapping>

    Still I get the error report I mentioned above.
    Does someone know what causes the throw of this ServletException?

    The interresting thing is that when I put the servlet (without the
    package declaration!) in
    the map "C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes" it
    works fine. No problem at all.
    So I think it has something to do with the packages structure and the
    environment settings.

    Who can help me out please?

    Thnx in advance

    Ron
     
    googleRon, Feb 25, 2006
    #1
    1. Advertising

  2. googleRon

    googleRon Guest

    At some lines in my message I mentioned by mistake Test2.
    Some of you might think that this is the problem, but that isn't.
    Where you read Test2 please replace it with Test1.
    Sorry if I caused some confusion with mentioning Test2.

    Greetings Ron
     
    googleRon, Feb 25, 2006
    #2
    1. Advertising

  3. googleRon wrote:
    > I tried to invoke a simple servlet "Test1" which is (just for testing
    > purposes) part of the package "myPackage" and its class-file is in
    > C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes\myPackage
    >
    > I get from Tomcat the following error-report:
    >
    > exception:
    > javax.servlet.ServletException: Error allocating a servlet instance
    >
    > root cause:
    > java.lang.NoClassDefFoundError: Illegal name: myPackage/Test2


    Tomcat is right: "myPackage/Test2" is not a legal class name.

    [...]

    > The first line in Test1.java is:
    > package myPackage;


    [...]

    > I adapted/edit web.xml bij adding the following lines:
    >
    > <servlet>
    > <servlet-name>Test1</servlet-name>
    > <servlet-class>myPackage/Test2</servlet-class>
    > </servlet>


    The class name should be "myPackage.Test2".

    [...]

    > The interresting thing is that when I put the servlet (without the
    > package declaration!) in
    > the map "C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes" it
    > works fine. No problem at all.


    I don't believe that. Specifically, I don't believe that Tomcat will
    ever load the servlet class if you tell it the name is
    "myPackage/Test2", no matter where you put the corresponding class file.

    --
    John Bollinger
     
    John C. Bollinger, Feb 26, 2006
    #3
  4. googleRon

    googleRon Guest

    Thnxalot John,
    This was really helpfull.
    A very stupid mistake of a rookie to put a / as separator in stead of a
    ..
    In reply to your last remark I forgot to mention that when I put the
    servlet in C:\...\classes I also changed the web.xml by deleting the
    prefix "myPackage/", so the statement is
    <servlet>
    <servlet-name>Test1</servlet-name>
    <servlet-class>Test1</servlet-class>
    </servlet>

    With regards,

    Ron
     
    googleRon, Feb 26, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohun Biswas
    Replies:
    0
    Views:
    453
    Mohun Biswas
    Jul 25, 2003
  2. Pia
    Replies:
    0
    Views:
    550
  3. HARI OM
    Replies:
    0
    Views:
    9,478
    HARI OM
    May 4, 2005
  4. Replies:
    0
    Views:
    3,653
  5. Dix
    Replies:
    0
    Views:
    11,969
Loading...

Share This Page