简体   繁体   中英

Where is servlet-api.jar in Glassfish 5.1?

Trying to build a Java web-site, i'm getting errors:

在此处输入图像描述

The import javax.servlet cannot be resolved

Some searching implies that in order to import javax.servlet you need a special jar file that comes with your web-server application server:

I did a search of the files in the installation folder of Glassfish 5.1. There is no servlet-api.jar . I so searched for any filenames that contain the words javax or servlet :

C:\Users\ian\GlassFish_Server\glassfish\modules

06/29/2022  11:37 AM            34,641 javax.batch-api.jar
06/29/2022  11:37 AM            95,067 jakarta.servlet-api.jar
06/29/2022  11:37 AM            66,437 jakarta.servlet.jsp-api.jar
06/29/2022  11:37 AM           561,358 jakarta.servlet.jsp.jar
06/29/2022  11:37 AM            56,706 jakarta.servlet.jsp.jstl-api.jar
06/29/2022  11:37 AM         3,689,362 jakarta.servlet.jsp.jstl.jar
06/29/2022  11:37 AM            26,966 jersey-cdi1x-servlet.jar
06/29/2022  11:37 AM            73,338 jersey-container-servlet-core.jar
06/29/2022  11:37 AM            32,135 jersey-container-servlet.jar
06/29/2022  11:37 AM            26,189 tyrus-container-servlet.jar

Which one of these files represents javax.servlet , and how would I know?

I did a grep of all the files in the folder, and none contain the ASCII text "javax.servlet".

Research Effort

As per the comments, you're looking for "jakarta.servlet-api.jar" in GlassFish 5.1.

"servlet-api.jar" is the old name of the artefact. Artefacts get renamed from time to time. Specifically after Java EE moved to the Eclipse foundation to become Jakarta EE, quite a few things got renamed.

You could have known by not looking for the jar name, but for which jars contain the actually classes you're looking for (eg use unzip -l recursively on all jar files in /modules and grep on that).

For some background on the move from Oracle to Eclipse, see https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM