Java

Teamcity - 包 javax.servlet 不存在

  • February 28, 2020

如何javax.servlet在 Teamcity 中導入?當我嘗試通過 teamcity IntelliJ IDEA 執行器建構 java 項目時,出現以下錯誤消息。

這是我第一次使用 teamcity,我正在使用這個https://github.com/marekbruchaty/SimpleJavaWebApp項目。我有一個具有 teamcity 和 gitlab 的 CentOS 伺服器。

在我的桌面上,使用 IntelliJ IDEA 我可以導入 servlet.api 來成功建構。但是 teamcity 在另一個位置並遠端管理,我想知道如何將 servlet-api 導入到 teamcity 中?

我應該在哪裡添加 servlet-api.jar 作為 teamcity 中的依賴項以便它可以編譯?

這是建構錯誤:

/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:1: package javax.servlet does not exist
import javax.servlet.ServletException;
                   ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
                        ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
                        ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:4: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
                        ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:5: package javax.servlet.annotation does not exist
import javax.servlet.annotation.WebServlet;
                              ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:13: cannot find symbol
 symbol: class HttpServlet
public class FormServlet extends HttpServlet {
                                ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:12: cannot find symbol
 symbol: class WebServlet
@WebServlet(name = "FormServlet")
^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:14: cannot find symbol
 symbol:   class HttpServletRequest
 location: class FormServlet
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                         ^
/root/buildAgent/work/f096a35a2a7f853/src/FormServlet.java:14: cannot find symbol
 symbol:   class HttpServletResponse
 location: class FormServlet

弄清楚了。

我必須將 servlet-api.jar 的路徑粘貼到 Build Step -> Project SDKs -> JDK Jar files patters 中。

引用自:https://serverfault.com/questions/1004451