aspose file tools*
The moose likes Beginning Java and the fly likes Need help in compiling java files within the same directory structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help in compiling java files within the same directory structure" Watch "Need help in compiling java files within the same directory structure" New topic
Author

Need help in compiling java files within the same directory structure

Diana Joseph
Greenhorn

Joined: Jun 09, 2008
Posts: 2
Hi,

I am practicing Head First Servlets and JSPs at the moment in
progress to my scwcd certification. I am struck in compiling java
file residing in the same directory structure.

I have a BeerExpert_model.class file in the directory
com.example.beermodel
and
BeerSelect.class file in the directory com.example.beer.
BeerSelect.class calls BeerExpert_model class. But the package,
com.example.beermodel isn't being recognised while compiling
BeerSelect.class.

I have copied both these classes below:




BeerSelect.java:

package com.example.beer;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.example.beermodel.BeerExpert_model;
import java.util.*;

public class BeerSelect extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String str = request.getParameter("color");
//out.println("<br>Get Beer Color "+str);
BeerExpert_model bem = new BeerExpert_model();
List result = bem.getBrands(str);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
Iterator it = result.iterator();
while(it.hasNext())
{
out.print("<br> try"+it.next());
}
}
}





BeerExpert_model.java:

package com.example.beermodel;
import java.util.*;
public class BeerExpert_model
{
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);
}
}



Please help me resolve this.

Thanks and regards,
Diana
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Think of the dots in the package name being translated to the slashes of directory structure: Where would everything be, or need to be put?
Diana Joseph
Greenhorn

Joined: Jun 09, 2008
Posts: 2
isn't that too correct in my scenario nicholas?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

This is a beginner's issue, really. It's all about your class path. See CompilingServlets for more info.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Don't get me started about those stupid light bulbs.
 
subject: Need help in compiling java files within the same directory structure