• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

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

Below is the folder structure for my development environment:



Problem
---------
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
D:\MyProjects\beerV1\src\com\example\model\

and class file in
D:\MyProjects\beerV1\classes\com\example\model\
and
C:\Tomcat\webapps\Beer-v1\WEB-INF\classes\com\example\model


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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Layne
 
straws are for suckers. tiny ads are for attractive people.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic