1
我正在從我們的網站Java代碼創建API以供客戶使用。我已經將該項目導出到eclipse中的JAR文件中。在一個單獨的測試項目中,我可以使用正確的功能從JAR調用某些方法。創建API
我在啓動引用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,它似乎不能正常工作(除非我做錯了什麼)。
在運行程序之前,您是否在類路徑中包含了servlet JAR? – Perception
我猜你錯了,但這取決於你實際想要做什麼。很明顯,你在執行期間錯過了類路徑上的servlet API或實現。 –
我的測試程序的類路徑中有servlet JAR,是的。它也包含在我原始代碼的類路徑中,用於創建我正在測試的JAR文件。 – jakewp11