Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

package does not exist problem

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

When i try the following program, it says package does not exist.




E:\progms\java\scwcdtests\beerV1>javac -d classes src/com/example/model/BeerExpe
rt.java
Note: src/com/example/model/BeerExpert.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.




E:\progms\java\scwcdtests\beerV1>javac -d classes src/com/example/web/BeerSelect
.java
src/com/example/web/BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src/com/example/web/BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src/com/example/web/BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors


help me in resolving this issue.
i already gone through similar topics but i am not able to understand the problem.
 
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you put the compiled class file?
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are compiling in command prompt, try setting the classpath to the com folder , I mean like this:
Classpath=%Classpath%;E:/..../com;

When you do this all the classes inside this package will be available.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are compiling a class having package like

package com.example.web;


So some needful like compile from the folder where these classes are,so if classes are in folder src,go till src and then compile.In your case you did a mistake that you are compiling one folder up from the desired one.

E:\progms\java\scwcdtests\beerV1\src>javac -d classes com/example/model/BeerExpert.java


Set the classpath to all the library required to compile and also the current directory.

SET CLASSPATH=%CLASSPATH%;E:\progms\java\scwcdtests\beerV1\classes;.(look at the .)

 
K Vidhyakar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

this is my class path.
D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;E:\progms\java\scwcdtests\beerV1\classes

when i compile ,

E:\progms\java\scwcdtests\beerV1>javac src/com/example/web/BeerSelect.java
src/com/example/web/BeerSelect.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/BeerSelect.java:5: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src/com/example/web/BeerSelect.java:9: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet {
^
src/com/example/web/BeerSelect.java:10: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
^
src/com/example/web/BeerSelect.java:10: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
^
src/com/example/web/BeerSelect.java:11: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
throws IOException, ServletException {
^
6 errors

now whats the problem...
 
Bear Bibeault
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This indicates that the servlet API is not in your classpath.

Check to make sure that your classpath has no typos or other errors and that it is in scope during compilation.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See:
http://faq.javaranch.com/view?CompilingServlets
for information regarding dependencies for compiling servlets.

Since this is really a javac/classpath issue and not servlet specific, I'm going to move the thread to Java In General (Beginner).
That is the best forum on this site for these types of problems.

-Ben
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic