ServletException vs packages

G

googleRon

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
 
G

googleRon

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
 
J

John C. Bollinger

googleRon said:
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.
 
G

googleRon

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top