命令窗口找不到类

目录结构: webapps | mytest | WEB-INF | classes | foo(package) | | Person BeanTest 问题如下: class 1: package foo; public class Person{ private String name; public void setName(String name){ this.name= name; } public String getName(){ return name; } } class 2: package foo; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class BeanTest extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException{ Person person1 = new Person(); person1.setName("dicky"); req.setAttribute("person",person1); RequestDispatcher dis=req.getRequestDispatcher("result.jsp"); dis.forward(req,res); } public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{ doPost(req,res); } } class 1 编译没有问题,但class 2编译的时候会出现找不到类 Person.它们是放在同一目录下啊,为什么会这样? 于是我做了一个测试 去掉2个类中的包申明,直接放在了classes包下面,再编译,全部通过。 于是我在classpath后面添加了classes的完整路径D:/Program Files/apache-tomcat-6.0.18/webapps/mytest/WEB-INF/classes,然后对class 2 再编译,通过了。
阅读更多

没有更多推荐了,返回首页