Forums Register Login

cannot compile

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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


+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
Thanks Balu. It worked
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 877 times.
Similar Threads
weird problem
Problem in accessing model in diffeerent package(Servlet-HFS)
package com.example.model does not exist
Ch3 Excercise in HFJS
can't import own model
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:28:48.