开发者

Regarding package in java

开发者 https://www.devze.com 2023-03-26 06:29 出处:网络
I have following directory structure. C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\Beer-v1\\WEB-INF\\classes\\com\\example\\model\\BeerExpert.java

I have following directory structure.

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes\com\example\model\BeerExpert.java

and

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes\com\example\web\BeerSelect.java

The source code for BeerSelect is

package com.example.web;
import com.example.model.*;
import开发者_运维问答 java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;


public class BeerSelect extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
String c=req.getParameter("color");
BeerExpert be=new BeerExpert();
List result=be.getBrands(c);
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("Beer Selection Advice<br>");
Iterator it=result.iterator();
while(it.hasNext())
{
out.println("<br>try: "+it.next());
}
}
}

and source code for BeerExpert is

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);
}
}

Beer Expert is compiling fine but whenevr i am running BeerSelect its giving me an error

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes\com\example\web\BeerSelect.java:2: package com.example.model does not exist
import com.example.model.*;
^
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes\com\example\web\BeerSelect.java:14: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes\com\example\web\BeerSelect.java:14: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();

^ 3 errors

Tool completed with exit code 1


Have you set the CLASSPATH to include BeerExpert? Include the *C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes* directory into the CLASSPATH


Looks like you are using the wrong build location. You need to be in WEB-INF\classes for the relative paths. IE, run this first:

cd "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes"

You might also have to add -classpath .;%CLASSPATH% to the command line argument.

Full command as requested:

C:\> cd "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Beer-v1\WEB-INF\classes"
C:\program files\apache\tomact 6\webapps\Beer-v1\WEB-INF\classes> javac -classpath .;%CLASSPATH% com\example\model\BeerExpert.java
0

精彩评论

暂无评论...
验证码 换一张
取 消