| Author |
Cannot Access Model Package, While Compiling Servlet
|
Rafi Fareen
Ranch Hand
Joined: Aug 28, 2009
Posts: 75
|
|
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
Joined: Nov 08, 2008
Posts: 72
|
|
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
|
Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
|
 |
Rafi Fareen
Ranch Hand
Joined: Aug 28, 2009
Posts: 75
|
|
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
Joined: Nov 08, 2008
Posts: 72
|
|
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
Joined: Aug 28, 2009
Posts: 75
|
|
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
Joined: Nov 08, 2008
Posts: 72
|
|
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
Joined: Aug 28, 2009
Posts: 75
|
|
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.
|
 |
 |
|
|
subject: Cannot Access Model Package, While Compiling Servlet
|
|
|