0

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

enter image description here

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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

1 Answers1

1

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 (e.g. 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

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140