• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

error: package com.example.model does not exist in BeerSelect.java

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

Question: What am i doing wrong that i get a compile error when adding the line "import com.example.model.*;" ?

I have read the other posts on "error: package com.example.model does not exist" and i believe those answers don't cover my issue.

When compiling the following code i get no error, it compiles fine.
I compile with: C:\MyProjects\beerV1>javac -classpath "C:/Tomcat/lib/servlet-api.jar" -d classes src/com/example/web/BeerSelect.java
And i get a class file: C:\MyProjects\beerV1\classes\com\example\web\BeerSelect.class
Thats Ok.



But when i add the line "import com.example.model.*;" i get the error message:

C:\MyProjects\beerV1>javac -classpath "C:/Tomcat/lib/servlet-api.jar" -d classes src/com/example/web/BeerSelect.java
src\com\example\web\BeerSelect.java:3: error: package com.example.model does not exist
import com.example.model.*;
^
1 error

code including "import com.example.model.*;"


My other class BeerExpert.java which compiles fine is as below and after compiling exists: C:\MyProjects\beerV1\classes\com\example\model\BeerExpert.class



Any idea what i do wrong?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's your classpath:
-classpath "C:/Tomcat/lib/servlet-api.jar"

At the moment that only includes the jar file in the classpath, it does not include the current directory, consequently javac cannot find any source files under that directory other than the one you've specified as the one to compile.

You need to add '.':
-classpath .;"C:/Tomcat/lib/servlet-api.jar"

(or it might be a : separator, I can never remember).
 
Arend van der Kolk
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With '.;' gives this error:



With '.:' gives this more errors:

 
Arend van der Kolk
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the other class "BeerExper.java does compile fine with the same command:

C:\MyProjects\beerV1>javac -classpath "C:/Tomcat/lib/servlet-api.jar" -d classes src/com/example/model/BeerExpert.java
Note: src\com\example\model\BeerExpert.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
 
Arend van der Kolk
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its working, ;-) wit the following command:

C:\MyProjects\beerV1>javac -classpath "C:/Tomcat/lib/servlet-api.jar";classes;. -d classes src/com/example/web/BeerSelect.java

What exactly does this ";classes;." mean?
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The purpose of the classpath is to specify the root location of the class files. Since you placed the class files in the "classes" directory with the "-d" option, you need to also specify that in your classpath... as it needs to search where you placed the class files.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic