This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Package not found error in JSP

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I am getting an error when importing a Package in JSP file saying "Package <name> not found". Why am I getting that error. Actually I worked with the same package in another directory and it was working fine. I copy pasted the "Java" file and the "Package" into a new directory where the JSP file in that new directory is not able to detect the package.

I deleted the package and recompiled the "Java" file to create the package again even that didn't work.

What could be the reason?

Can anyone give me a detailed explanation where I am going wrong or what is the reason?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSPs don't look in the current directory for Java classes.

The class loadeders in J2EE weabpps look in a specific list of directories for Java classes.
Your package directory structure should go under WEB-INF/classes.
If you classes are packed in jars, the jar files should go under WEB-INF/lib

You then need to import any classes/packages that you want to use in your JSP.
Look up the <%@page import ...%> and the <jsp:useBean /> tags in the JSP spec (link in my signature).
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben

Thanks for your clarifications on the error message.

But I am working with TOMCAT4.1.24. I created a Bean class in WEB-INF/classes "folder" and compiled there itself to create the package. My Bean class name is WBean.java
and Package name is WMonitoring

I imported my bean class using

<%@ page import="java.util.*, WMonitoring.*"%>
and created Bean instance using:

WBean wb=new WBean();

I got the compilation error :

cannot resolve symbol

symbol : class WBean
[javac] location: class org.apache.jsp.WorkDelegation_jsp
[javac] WBean wb=new WBean();


Then I tried to create instance using:

WMonitoring.WBean wb=new WBean()

Even then I am getting error

cannot resolve symbol

symbol : class WBean
[javac] location: package WorksMonitor
[javac] WorksMonitor.WBean wb=new WBean();

Can you clarify this....

I am using the same Bean class in another JSP file in some other Folder, where it is working fine without any changes. I just made a copy of the entire thing and did some modifications to my current JSP.
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone clarify my question, why I am getting Package not found error
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you creating the package folder under WEB-INF/classes or just dumping the class file there?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure that

1. You have WEB-INF/classes/WMonitoring/WBean.class
2. WBean is a public class


Note:
You should give lowercase names to your packages.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If, after following Bear's and Satou's suggestions, this is still not working, post the code to your bean (please be sure to use the UBB code tags) and list the exact location of your bean's class file on your file system.
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is my code in WBean.java class which I am going to use in my JSP's.

I have created this bean class file in webapps/myProject/WEB-INF/classes folder of Tomcat and compiled it to create package: WMonitoring, upon successful compilation of the "bean" file I got pacakage WMonitoring which is in classes directory.

Path for WMonitoring folder:

webapps/myProject/WEB-INF/classes/WMonitoring

When I create instance of the above WBean class in my jsp, as

I am importing the package using tag in my jsp.

I am creating instance of WBean class which is already declared "Public" as:

WBean wb=new WBean(); //I got error here
again I tried creating instance of Bean class using

WMonitoring.WBean wb=new WBean(); //even here I am getting error


Given the details above, can anyone clarify me where actually I am going wrong? I am using the same file in another folder and Iam using it without any errors..
[ July 20, 2006: Message edited by: Sree Mami ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you should try to rename your package with lowercase
WMonitoring -> wmonitoring

Are you under Windows ?

And please clarify this:

I am using the same file in another folder and Iam using it without any errors


Show us what you're doing there.
[ July 20, 2006: Message edited by: Satou kurinosuke ]
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

Thanks for your early reply...

As suggested by you, I even tried renaming my package in "lowercase" but still the problem persists. I didn't do any changes to the above "Bean" class but it's all working well in another Folder in which I practice some programs and upon successful compilation there I just dump those files into "myproject" folder where actually all of my files related to my project are stored.

Yes I am using Windows 2000 Server with Tomcat 4.1.24, Internet explorer: 6. What could be the possible error.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sree Mami,
As per your code you have pasted there is an error in the import. You should not use include for importing a package. Use <%@ page import="WMonitoring.*" %> Try with this.


Thanks.
Ganesh
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ganesh

Sorry, it was my typing mistake in my earlier reply. I actually imported my package as:

<%@ page import="java.util.*, WMonitoring.*" session="true"%> and even tried giving package name in "lowercase".

What could be the problem?
[ July 20, 2006: Message edited by: Sree Mami ]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have created this bean class file in webapps/myProject/WEB-INF/classes folder of Tomcat and compiled it to create package: WMonitoring, upon successful compilation of the "bean" file I got pacakage WMonitoring which is in classes directory



From the command prompt traverse to the webapps/myProject/WEB-INF/classes folder and run the following command and post the output:



This will show the contents(and the hierarchy) of your application(just to make sure that the packaging of your application is correct)
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi JaiKiran

This is what I got when I executed dir/b/s at my command prompt:


C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes>dir/b/s
C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes\WBean.java
C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes\WMonitoring
C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes\WMonitoring\WBean.class

C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes>

This is the Error message I am getting when I am loading my JSP file on Tomcat:


org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\WorksMonitoring\WorkDelegation_jsp.java:9: package WMonitoring does not exist
[javac] import WMonitoring.*;
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\WorksMonitoring\WorkDelegation_jsp.java:23: package WMonitoring does not exist
[javac] WMonitoring.WBean wb=new WBean();
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\WorksMonitoring\WorkDelegation_jsp.java:23: cannot resolve symbol
[javac] symbol : class WBean
[javac] location: class org.apache.jsp.WorkDelegation_jsp
[javac] WMonitoring.WBean wb=new WBean();
[javac] ^
[javac] 3 errors


Here I am using: WMonitoring.WBean as I thought Package name prefixed would atleast recognize the Bean class "WBean" but even it didn't work. I tried even changing my package name to lowercase even.


 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried your application(just created a sample jsp and a package and class with the same name as yours) on my machine. It worked fine. Then after reading your posts again, this is something that i found:

C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes\WMonitoring\WBean.class



Shouldnt your WEB-INF directory be directly under either the "Project" folder or "WorksMonitoring" folder?
I tried doing the same as you have done, i created a folder under webapps named myProject and inside that i placed WorksMonitoring folder(which contains the WEB-INF folder). Interestingly, the application did *not* even get deployed, because the server could not find the WEB-INF folder, directly under "myProject". Same thing should have happened in your case, the application should not have been deployed and you should have seen 404 error. However as your logs suggest, the application is getting deployed.

Then i tried one more thing. I *copied* the WEB-INF folder present in the webapps/myProject/WorksMonitoring folder and put it in webapps/myProject folder. I then deleted the WMonitoring package from the classes folder present in webapps/myProject/WEB-INF directory. So effectively, i have the following hierarchy in place:



Note that there are 2 WEB-INF folders present at different locations. The WEB-INF which is directly inside the myProject folder does *not* contain the WMonitoring package.

I then tried out the jsp and even i ran into the same package does not exist exception.

Conclusion is that you are having the WEB-INF/classes/WMonitoring/ package at the wrong place. You should have it as:


and *not*

C:\Program Files\Apache Group\Tomcat 4.1\webapps\Project\WorksMonitoring\WEB-INF
\classes\WMonitoring



P.S.: I am not great at Tomcat, this is just based on my observations after trying out a sample application on my machine.
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi JaiKiran

Really, it was the problem which you have concluded. Thanks for helping me out; otherwise I would have gone clueless as of why this error has occured. Great piece of observation!!!

You have given me a great detailed explanation, though it was a minor error it needs to be taken care of.

Thanks a lot for that.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this WorksMonitoring ? You were not talking about this first.
You said "I have created this bean class file in webapps/myProject/WEB-INF/classes".

Then it becomes "webapps\Project\WorksMonitoring\WEB-INF".

Please be careful when asking questions, that could save you and us time.

though it was a minor error it needs to be taken care of.


Don't take this lightly, it's a major error, breaking J2EE specification.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
What is this WorksMonitoring ? You were not talking about this first.
You said "I have created this bean class file in webapps/myProject/WEB-INF/classes".

Then it becomes "webapps\Project\WorksMonitoring\WEB-INF".

Please be careful when asking questions, that could save you and us time.


Don't take this lightly, it's a major error, breaking J2EE specification.




Agreed.
In fact we have an entry in our HowToAskQuestionsOnJavaRanch FAQ that covers this type of problem.
You can read it here.
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

Thanks for all your efforts in solving my problems. Ya, I would be bit careful in explaining the whole problem hereafter.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad it's working for you.
 
Everybody's invited. Except this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic