我正在从我们的网站 Java 代码创建一个 API 供我们的客户使用。我已将项目导出到 Eclipse 中的 JAR 文件。在一个单独的测试项目中,我能够从具有正确功能的 JAR 中调用某些方法。
当我启动一个引用 javax.servlet.http.HttpRequestServlet 的类的新对象 (TrackingAction) 时,我遇到了问题。我收到以下错误
The import javax.servlet.http.HttpServletRequest cannot be resolved
The import javax.servlet.http.HttpSession cannot be resolved
HttpSession cannot be resolved to a type
HttpSession cannot be resolved to a type
这是我要开始工作的代码:
import com.myproject.api.data.ShipmentDetail;
import com.myproject.api.data.ShipmentSummary;
import com.myproject.api.service.ShipmentService;
import com.myproject.web.project.action.TrackingAction;
public class Main{
public static void main(String[] args){
ShipmentSummary shipSum = new ShipmentSummary();
ShipmentDetail shipDet = new ShipmentDetail();
TrackingAction trAction = new TrackingAction(); //ERROR COMES FROM THIS LINE
ShipmentService shipServ = trAction.getShipmentService();
List<ShipmentSummary> lss = shipServ.getShipmentSummaryByProNumber("101844564");
List<ShipmentDetail> lsd = shipServ.getShipmentDetail(lss.get(0));
shipDet = lsd.get(0);
shipSum = lss.get(0);
System.out.println("Summary status: " + shipSum.getStatus());
System.out.println("Detail pickup: " + shipDet.getPickupNumber());
}
}
我找遍了所有地方,但找不到可行的解决方案。我试过使用 ClassLoaders 没有成功。我试过 OneJar,但它似乎不能正常工作(除非我做错了什么)。