File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes need help when compile the code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "need help when compile the code" Watch "need help when compile the code" New topic
Author

need help when compile the code

jess Chiu
Greenhorn

Joined: Jan 29, 2002
Posts: 20
//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

Joined: Nov 24, 2005
Posts: 14687
    
  16

How did you compile ? Make sure that the foo package is in the classpath.


[My Blog]
All roads lead to JavaRanch
jess Chiu
Greenhorn

Joined: Jan 29, 2002
Posts: 20
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Jan 29, 2002
Posts: 20
I tried your command, still the same

How can I specify "foo" in classpath?

Thanks a lot
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Sorry, it was not "." but "..":
javac -classpath /tomcat/common/lib/servlet-api.jar;.. BeerSelect.java
jess Chiu
Greenhorn

Joined: Jan 29, 2002
Posts: 20
great!!! thanks

one little dot make so much difference
jess Chiu
Greenhorn

Joined: Jan 29, 2002
Posts: 20
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

Joined: Jan 26, 2006
Posts: 169
Make sure that the foo package is in the classpath.

You must set . in the CLASSPATH environment variable.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You need a different JAR :

javac -classpath /tomcat/common/lib/servlet-api.jar;/tomcat/common/lib/jsp-api.jar;.. BeerSelect.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help when compile the code