This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Compiling servlet version two code in HFSJ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Compiling servlet version two code in HFSJ" Watch "Compiling servlet version two code in HFSJ" New topic
Author

Compiling servlet version two code in HFSJ

Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13
Errors: i am getting while compiling, i have created the same directory structure given in HFSJ, can some one help me to proceed ?
C:\Servlets\Beer-v1\src\com\example\web>javac BeerSelect.java
BeerSelect.java:3: package src.com.example.model does not exist
import src.com.example.model.*;
^
BeerSelect.java:16: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
BeerSelect.java:16: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Hi Nalla

Do one thing
Go to this destination C:\Servlets\Beer-v1\src> in your command prompt.
Now execute the command
javac com/example/web/BeerSelect.java

Or the best way is to create a classes directory inside your src directory and then executing this command from the same destination.

javac -d classes com/example/web/BeerSelect.java

Now just copy the classes directory to your WEB-INF directory.

Regards,
Khushhal


rgrds,
Khushhal
Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13

Errors:C:\Servlets\Beer-v1\src>javac com/example/web/BeerSelect.java
com\example\web\BeerSelect.java:17: cannot access com.example.web.BeerExpert
bad class file: .\com\example\web\BeerExpert.java
file does not contain class com.example.web.BeerExpert
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
BeerExpert be=new BeerExpert();
^
1 error

Thanks Kushal , help ?
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Nalla, tell me
Where is your class BeerExpert located?
Exact path location..
If possible paste it's source code also.

Regards,
Khushhal
Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13

path:C:\Servlets\Beer-v1\src\com\example\model\BeerExpert.java

BeerSelect.java


path:C:\Servlets\Beer-v1\src\com\example\web\BeerSelect.java

khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Nalla, see what's happening

Errors:C:\Servlets\Beer-v1\src>javac com/example/web/BeerSelect.java
com\example\web\BeerSelect.java:17: cannot access com.example.web.BeerExpert
bad class file: .\com\example\web\BeerExpert.java


It's looking for BeerExpert in web folder.
But your BeerExpert is in model folder.

So, in BeerSelect..
Instead of writing
import com.example.model.*;
Try with
import com.example.model.BeerExpert;

Otherwise, it should execute fine.

Regards,
Khushhal
Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13
Thanks kushal for supporting, i am trying to execute for 3 days could not do it. i am getting the same errors

C:\Servlets\Beer-v1\src\com\example\web>javac BeerSelect.java
BeerSelect.java:3: package com.example.model does not exist
import com.example.model.BeerExpert;
^
BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Did you get it now???

Regards,
Khushhal
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Nalla,

Try it in the way, I explained above.
You will get it.

Just now, I tried with your source code only without any modification and got compilation success.
C:\jakarta-tomcat-5.0.28\webapps\Testing\WEB-INF\src>javac com/example/web/BeerSelect.java
Note: .\com\example\model\BeerExpert.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

C:\jakarta-tomcat-5.0.28\webapps\Testing\WEB-INF\src>


See what was happening in your case, once you are in web, compiler has no way to look outside this.
So there is no way, compiler will be able to find model.
Hence you were getting those errors.

You can compile from any of the folder which is parent for both web and model.

Regards,
Khushhal
[ August 22, 2007: Message edited by: khushhal yadav ]
Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13
it is showing these errors while compiling ,can you tell me where to check for this errors

C:\Servlets\Beer-v1\src\com\example\web>javac BeerSelect.java
BeerSelect.java:3: package com.example.model does not exist
import com.example.model.BeerExpert;
^
BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors

thank you
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Nalla

See what is happening in your case, once you are in web, compiler has no way to look outside it.
So there is no way, compiler will be able to find model.
Hence you are getting those errors.

You can compile it from any of the folder which is common parent for both web and model.

So compile it in the way, I explained above.

Go to this destination C:\Servlets\Beer-v1\src> in your command prompt.
Now execute the command
javac com/example/web/BeerSelect.java

Or the best way is to create a classes directory inside your src directory and then executing this command from the same destination.

javac -d classes com/example/web/BeerSelect.java


Your problem will be solved.
Still you face problem, let me know.

Regards,
Khushhal
Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13
it works


Thanks kushal for your continuing support
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Nalla now Happy

Keep Smiling.. A Smile is something which never takes anything away from anyone. On the other hand helps to impart Smiles to others.

Regards,
Khushhal
[ August 22, 2007: Message edited by: khushhal yadav ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

That sounds very rude, but do you have SCJP ? You need it to pass SCWCD.


[My Blog]
All roads lead to JavaRanch
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Hi Christophe

But none of us has been rude at any time.
And it's not only Nalla, I have seen many people who faced such kind of problem.
They find it difficult while dealing with packages.
There is nothing wrong in it. It's OK.
While preparing for SCJP, they might not have much exposure to such kind of thing.

Regards,
Khushhal
Nalla Balu
Greenhorn

Joined: Aug 15, 2007
Posts: 13
Thanks Kushal

got 75% scjp5 three months ago
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Compiling servlet version two code in HFSJ
 
Similar Threads
help for HFSJ - CH 3 Page 84
Mistakes in HFSJ
Trouble compiling servlet HFSJ pg 85
problem while compiling
Unable to compile Packge servlet