• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

cannot compile

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Balu. It worked
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic