• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiling servlet version two code in HFSJ

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Nalla Balu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you get it now???

Regards,
Khushhal
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it works


Thanks kushal for your continuing support
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds very rude, but do you have SCJP ? You need it to pass SCWCD.
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kushal

got 75% scjp5 three months ago
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic