File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Package doesn't exists - error!!- How to resolve? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package doesn Watch "Package doesn New topic

Package doesn't exists - error!!- How to resolve?

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129

Below is the folder structure for my development environment:

I am learning MVC and for that I tried to execute the simple program which includes Plain Java Coding(Model), Servlet(Controller) and JSP and HTML(View).

Actually, I want to compile the servlet in which it creates the instance of the class (BeerExpert) and use the method of that class BeerExpert.

While I compiling I am getting the package no found error:

The code I am executing:

Servlet Coding(Controller):

The Plain Java Code(Model)
It's source file has been kept in

and class file in

I compiled the above java coding as below:

For Java - Compiler Option
D:\MyProjects\beerV1\src>javac -classpath c:\Tomcat\common\lib\servlet-api.jar -d ..\classes \com\example\model\

By above the class file for BeerExpert has been automatically placed at D:\MyProjects\beerV1\classes\com\example\model

For Servlet - Compiler Option
D:\MyProjects\beerV1\src>javac -classpath c:\Tomcat\common\lib\servlet-api.jar -d ..\classes \com\example\web\

When I tried to compile the Servlet by same, it's geenrating the error message as
com/example/model pacakge doesn't exists;

Why this error is occuring? How to resolve it?
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
You are getting this error because the package can not be found by the compiler.

In order to compile correctly you will have to set the classpath so it includes the "D:\MyProjects\beerV1\classes" folder in which the other classes are located.

So you should start compiling using something like this:

D:\MyProjects\beerV1\src>javac -classpath c:\Tomcat\common\lib\servlet-api.jar;D:\MyProjects\beerV1\classes -d ..\classes \com\example\web\

This should fix your problem.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I like Manuel's suggestion since you can type that command from any directory, but in case it doesn't work, you can also change to the classes subdirectory and use your original command.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Package doesn't exists - error!!- How to resolve?
It's not a secret anymore!