Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot compile

 
Layla Rashid
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to compile this java file :
========================
package com.example.web;

import java.io.*;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.model.BeerExpert;


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
");
String c = request.getParameter("color");
//out.println("
Got beer color " + c);
BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while(it.hasNext()){
out.print("
try: " + it.next());
}

}

}

============
in the command line I used :
C:\Program Files (x86)\Java\jdk1.5.0_20\bin>javac -classpath C:\Sun\SDK\lib\j2ee.jar -d . JavaSelect.java

Before that I already compile BeerExpert.java file.
C:\Program Files (x86)\Java\jdk1.5.0_20\bin>javac -Xlint:unchecked -classpath C:\Sun\SDK\lib\j2ee.jar -d . BeerExpert.java

here is the BeerExpert.java file:
==============================
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;
}

}
========================
it's class file got created here
C:\Program Files (x86)\Java\jdk1.5.0_20\bin\com\example\model

Now when I try to compile BeerSelect file I get these errors:

C:\Program Files (x86)\Java\jdk1.5.0_20\bin>javac -classpath C:\Sun\SDK\lib\j2ee
.jar -d . BeerSelect.java
BeerSelect.java:11: package com.example.model does not exist
import com.example.model.BeerExpert;
^
BeerSelect.java:24: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
BeerSelect.java:24: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors

------------------
please help ... I wonder how to solve these.

thanks
Layla
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Layla,

default classpath is current directory "." , if you override classpath in javac option , add "." also

run like this
javac -classpath C:\Sun\SDK\lib\j2ee.jar;. BeerSelect.java


 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd love to check your code, but I don't feel like working through unformatted code. Please put the code between the code tags..
 
Layla Rashid
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Balu. It worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic