This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile error

 
Suja Mudunuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 classes as below from book HFS and JSP page 84.

package com.example.model;
import java.util.*;

public class BeerExpert{
public List getBrands(String color){
List brands = new ArrayList();
if(color.equals("amber")){
brands.add("Jack Amber");
brands.add("Red Moose");
}else{
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}
return(brands);
}
}
This class compiles fine
I Am importing the above class in the following Servlet class

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer selection Advice<br>");
String c = request.getParameter("color");

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while(it.hasNext()){
out.print("<br>try: " + it.next());
}
}
}
I keep getting the following error
src/com/example/web/BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src/com/example/web/BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src/com/example/web/BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors

I do have a class in this path C:\Sujatha\MyProjects\beerV1\classes\com\example\model

Can somebody please help be with what I am doing wrong?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Suja Mudunuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do I need to have in my classpath?
Do I need to put my package path? C:\Sujatha\MyProjects\beerV1\classes\com\example\model
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No class path should be your parent directory

set path to here C:\Sujatha\MyProjects\beerV1\classes\

Then refer your package relative to this like com.example......

Nikhil Kanjulli Menon
SCJP1.4
 
Suja Mudunuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Nikhil for the immediate response. I am able to compile now.
 
Tim Meyers
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what I'm missing here. I just can't seem to get it to compile. My compile string is "javac -classpath c:\tomcat\common\lib\servlet-api.jar -d classes src\com\example\web\BeerSelect.java" in a command window. I've been trying to resolve this for hours, and can't seem to make any progress.

Any help?
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timothy,

What error are you getting?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the look of it, you also need your own classes on the classpath, not just the servlet jar. Try something like this:



No promise, but that's my guess.

Dave
 
Tim Meyers
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did the trick.

Thanks
 
Greg Helton
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you change directories to src and change the compile command to

"javac -classpath c:\tomcat\common\lib\servlet-api.jar -d ..\classes com\example\web\BeerSelect.java"

I start my compile with the package directory (not from "src" above "com"). And, I find ANT helps eliminate compilation problems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic