Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help when compile the code

 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//BeerSelect.java

package foo;

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{

java.util.Date today = new java.util.Date();

String c=request.getParameter("color");

BeerExpert be = new BeerExpert();
List result= be.getBrands(c);

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("beer selection advice");

Iterator it=result.iterator();

while(it.hasNext()) {
out.println("<br>try"+ it.next());
}
}

}


//BeerExpert.java


package foo;


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("Rose Amber");
}

else{
brands.add("Jail pale Ale");
brands.add("Gout Stout");
}

return brands;


}

}


when I compile the 2 classes "in same directory".
the only mistake is the compiler always tell me can not found BeerExpert,

BeerExpert be = new BeerExpert();

Anyone can help me figure out? Thanks a lot
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you compile ? Make sure that the foo package is in the classpath.
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cd into foo directory, the 2 class all under this directory.

1) I type: javac BeerExpert.java
and found BeerExpert.class in foo directory

2) I type: javac -classpath /tomcat/common/lib/servlet-api.jar BeerSelect.java

and got this error message

BeerExpert be= new BeerExpert();
can not found BeerExpert

Thanks a lot
jess
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the -classpath command line argument, you have to specify that foo must be in the classpath :
javac -classpath /tomcat/common/lib/servlet-api.jar;. BeerSelect.java
or in Unix:
javac -classpath /tomcat/common/lib/servlet-api.jar:. BeerSelect.java
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried your command, still the same

How can I specify "foo" in classpath?

Thanks a lot
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, it was not "." but "..":
javac -classpath /tomcat/common/lib/servlet-api.jar;.. BeerSelect.java
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great!!! thanks

one little dot make so much difference
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;


Need help again. I use same command to complie a tag class, But compiler can not find javax.servlet.jsp.tagext.*; and javax.servlet.jsp.*;


Thanks a lot
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that the foo package is in the classpath.

You must set . in the CLASSPATH environment variable.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a different JAR :

javac -classpath /tomcat/common/lib/servlet-api.jar;/tomcat/common/lib/jsp-api.jar;.. BeerSelect.java
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic