Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

package com.example.model does not exist

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package com.example.model does not exist

This is an example in Chapter3 of HFSJ

the directory structure is as follows...

C:\Tomcat\MyProject\beerV1\src\com\example\web\BeerSelect.java
C:\Tomcat\MyProject\beerV1\src\com\example\model\BeerExpert.java
C:\Tomcat\MyProject\beerV1\classes\com\example\web\
C:\Tomcat\MyProject\beerV1\classes\com\example\model\BeerExpert.class

and my tomcat directory is...

C:\Tomcat\$CATALINA_HOME\apache-tomcat-5.5.20\common\lib\servlet-api.jar

My BeerSelect.java code is...

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while(it.hasNext()) {
out.println("<br>try: " + it.next());
}
}
}

My BeerExpert.java code is...

package com.example.model;

import java.util.*;

public class BeerExpert {
public List getBrands(String color){
List brands = new ArrayList();
if (color.equals("amber")) {
brands.add("Jack Amber");
brands.add("Red Moose");
}
else {
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}
return(brands);
}
}

I have my CLASSPATH in (C:\AUTOEXEC.bat) set as...

set PATH=C:\Program Files\Java\jdk1.5.0_10\bin;C:\WINDOWS\java;C:\WINDOWS\java\classes;C:\WINDOWS\java\trustlib;%PATH%
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_10

Also in Environment Variables under User Variables, I have set my CLASSPATH as...

CLASSPATH C:\Program Files\Java\jdk1.5.0_10;C:\WINDOWS\java;C:\WINDOWS\java\classes;C:\WINDOWS\java\trustlib;

Also in Environment Variables under System Variables, I have appended the following to the CLASSPATH as...

CLASSPATH C:\Program Files\Java\jdk1.5.0_10\bin;

I am trying to compile the BeerSelect.java program as...

C:\Tomcat\MyProjects\beerV1>javac -classpath C:\Tomcat\$CATALINA_HOME\apache-tom
cat-5.5.20\common\lib\servlet-api.jar -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:16: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src/com/example/web/BeerSelect.java:16: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors

C:\Tomcat\MyProjects\beerV1>

Any clue why it is not picking up the other package class file???
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "Gem Guy"-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, you need to have the missing class file in your classpath, which currently you do not. Add the "classes" directory to your classpath, and it should work.
 
John Adkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where in classpath do you want me to add the missing class, could you please describe it
 
Ulf Dittmer
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of

javac -classpath C:\Tomcat\$CATALINA_HOME\apache-tomcat-5.5.20\common\lib\servlet-api.jar ...

try

javac -classpath classes;C:\Tomcat\$CATALINA_HOME\apache-tomcat-5.5.20\common\lib\servlet-api.jar ...

I'm surprised that it doesn't complain about missing servlet classes too; what value does the CATALINA_HOME variable have - is it empty?
 
John Adkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf, your solution worked for me, Thank You very much.


You asked me for the CATALINA_HOME variable value, but where should i look for its value???
 
Ulf Dittmer
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you don't know what CATALINA_HOME is, then you probably didn't set it, and it's empty. In that case, you could just use:

javac -classpath classes;C:\Tomcat\apache-tomcat-5.5.20\common\lib\servlet-api.jar
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic