java编译为什么路径会不对

图片说明
下面一条编译里面 import com.example.model.*;老是报错
问题是看上面一条,路径没有问题啊
我中间试了试import com.example.*;或者import com.example.web*;import语句就没问题,报错只是是因为BeerExpert找不都没有import进来。

代码
package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.example.model.*;
import java.util.*;

public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException{

    String c = request.getParameter("color");
    BeerExpert be = new BeerExpert();
    List result = be.getBrands(c);

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

目录结构图片说明

提示的是包不存在,你的包和路径对应么?大小写、文件名是否对应。model是放在model.java的么?是public的么?

This works:

com/example/model/BearExtra.java

package com.example.model;

public class BearExtra {
public static void go() {
System.out.println("Yay, it works!");
}
}
com/example/web/Bear.java

package com.example.web;

import com.example.model.*;

public class Bear {
public static void main(String[] args) {
BearExtra.go();
}
}

Now, to compile and run these classes, go to the directory where you can "see" the com folder and do:

**nix/MacOS*

javac -cp . com/example/model/*.java com/example/web/*.java
java -cp . com.example.web.Bear

Windows

javac -cp . com\example\model*.java com\example\web*.java
java -cp . com.example.web.Bear

and the following is being printed to the console:

Yay, it works!

解答来源于国外网站stackoverflow(credit)
给个币吧

图片说明

当前类是处于web包里面的, 因此他只能在web包里面找到当前类