• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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\BeerExpert.java

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\BeerSelect.java

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?
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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\BeerSelect.java

This should fix your problem.
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic