• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Arend van der Kolk
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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?
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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?
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!