Difference between javax.servlet-api.jar vs servlet-api.jar

后端 未结 5 496
囚心锁ツ
囚心锁ツ 2021-01-01 14:05

In my maven repository under groupId javax.servlet i have these two separate artifacts for servlets. I am confused which one should i use to build a simple serv

5条回答
  •  离开以前
    2021-01-01 14:22

    For those using gradle...

    If I declare my dependency using compileOnly as below

    compileOnly "javax.servlet:javax.servlet-api:3.1.0"
    

    then I get a compilation error:

    error: package javax.servlet.http does not exist
    import javax.servlet.http.HttpServletRequest;
                             ^
    

    If I use providedCompile as below the build is successful.

    providedCompile "javax.servlet:javax.servlet-api:3.1.0"
    

    To use providedCompile dependencies you need to use the war plugin.

    apply plugin: 'war'
    

提交回复
热议问题