This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot Access Model Package, While Compiling Servlet

 
Rafi Fareen
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i'm reading this book named HFSJ and came across the first example.
having trouble with accessing packages.

my path is set to: D:\java\Development Area\Beer-v1

other java_home & tomcat_home paths are correct [because i have tested a servlet and its working].

there is a example that uses MVC architecture [beer example, of the same book].

so my development directory structure is:

D:\java\Development Area\Beer-v1\src\com\example\web\SelectBeer.java [servlet]

D:\java\Development Area\Beer-v1\src\com\example\model\GebBeers.java [plain java class]

as well the classes [have same structure as above, created while compilation with -d option]


my plain java code


my servlet code


i compile plain java file :

javac -d classes src/com/example/model/GetBeers.java [works, compiles and stores the .class file in classes directory structure]
but
javac -d classes src/com/example/web/SelectBeer.java [gives compilation error, while importing package model .... ]

i guess i'm missing something [maybe my classpath is not correct] or
maybe the import statement is looking into : src/com/example/model rather than looking in classes/com/example/model ......

any solution,

regards,

Rafi

 
Swagato Bhatta
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac -classpath /apache-tomcat-6.0.18/apache-tomcat-6.0.18/lib/servlet-api.jar;classes;. -d classes src\com\example\web\SelectBeer.java

The first classpath tells where the servlet-api is located.
The second ones (probably) stating that "Please look inside the classes"
ALso . (probably) stands for "look in the current directory/folder too"

Please some correct me if I am wrong
 
Rafi Fareen
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swagato Bhatta wrote:javac -classpath /apache-tomcat-6.0.18/apache-tomcat-6.0.18/lib/servlet-api.jar;classes;. -d classes src\com\example\web\SelectBeer.java

The first classpath tells where the servlet-api is located.
The second ones (probably) stating that "Please look inside the classes"
ALso . (probably) stands for "look in the current directory/folder too"

Please some correct me if I am wrong



i have the servlet-api.jar and jsp-api.jar in my classpath. i have mentioned that i can run the servlets, but here i'm facing little of package access problem, not servlet problem.
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafi Fareen wrote:
Swagato Bhatta wrote:javac -classpath /apache-tomcat-6.0.18/apache-tomcat-6.0.18/lib/servlet-api.jar;classes;. -d classes src\com\example\web\SelectBeer.java

The first classpath tells where the servlet-api is located.
The second ones (probably) stating that "Please look inside the classes"
ALso . (probably) stands for "look in the current directory/folder too"

Please some correct me if I am wrong



i have the servlet-api.jar and jsp-api.jar in my classpath. i have mentioned that i can run the servlets, but here i'm facing little of package access problem, not servlet problem.


See the second class path is to find the classes inside the classes folder and third one if any in current folder. ...Umm have you tried my solution and checked if it worked? I have a feeling it will work. By stating where you package is (in other words where the classes of the package is) your app will work. Just try out ok in command prompt. Thanks
 
Rafi Fareen
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swagato Bhatta wrote:javac -classpath /apache-tomcat-6.0.18/apache-tomcat-6.0.18/lib/servlet-api.jar;classes;. -d classes src\com\example\web\SelectBeer.java

The first classpath tells where the servlet-api is located.
The second ones (probably) stating that "Please look inside the classes"
ALso . (probably) stands for "look in the current directory/folder too"

Please some correct me if I am wrong


javac -classpath classes -d classes src/com/example/web/SelectBeer.java [works fine.]

Thanks for the hint Swagato.

 
Swagato Bhatta
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafi Fareen wrote:
Swagato Bhatta wrote:javac -classpath /apache-tomcat-6.0.18/apache-tomcat-6.0.18/lib/servlet-api.jar;classes;. -d classes src\com\example\web\SelectBeer.java

The first classpath tells where the servlet-api is located.
The second ones (probably) stating that "Please look inside the classes"
ALso . (probably) stands for "look in the current directory/folder too"

Please some correct me if I am wrong


javac -classpath classes -d classes src/com/example/web/SelectBeer.java [works fine.]

Thanks for the hint Swagato.



You are welcome !
 
Rafi Fareen
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafi Fareen wrote:
Swagato Bhatta wrote:javac -classpath /apache-tomcat-6.0.18/apache-tomcat-6.0.18/lib/servlet-api.jar;classes;. -d classes src\com\example\web\SelectBeer.java

The first classpath tells where the servlet-api is located.
The second ones (probably) stating that "Please look inside the classes"
ALso . (probably) stands for "look in the current directory/folder too"

Please some correct me if I am wrong


javac -classpath classes -d classes src/com/example/web/SelectBeer.java [works fine.]

Thanks for the hint Swagato.




i have screwed up my brain by declaring the "classes" folder in the environment variable, but never worked from there ... i guess because of the relative/absolute stuff ... anyways i'm not good with packaging.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic