Issue
I know there are many old questions regarding this topic: 1, 2, 3
But I am using a different approach in for my pretty straight forward servlet.
Setup
- Tomcat 9
- Maven for clean builds and managing dependencies
- Jersey
- Eclipse 2021-09 (4.21.0)
I am not using a web.xml
, like this:
4.7.2.1. Descriptor-less deployment
There are multiple deployment options in the Servlet 3.0 container for a JAX-RS application defined by implementing a custom Application subclass. For simple deployments, no web.xml is necessary at all. Instead, an @ApplicationPath annotation can be used to annotate the custom Application subclass and define the base application URI for all JAX-RS resources configured in the application:
Example there
@ApplicationPath("resources")
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("org.foo.rest;org.bar.rest");
}
}
I have updated Jersey from 2.32 to 3.0.1, all dependencies are downloaded an there no compile error when I run mvn clean package
.
When I run the Tomcat server in Eclipse, my second servlet is started, but something goes wrong with the Jersey 3-one. The frustrating part is that there is absolutely no error.
Update
I have changed the toolset and go for
- Tomcat 10
- jakarta.* namespace instead of javax.* namespace
- Using
<artifactId>jakarta.servlet-api</artifactId>
Maybe I am missing some stupid thing (in my dependencies), but since there is no documentation for migration apart from switch to Jakarta, it is an trial and error thing.
Here is my list of relevant dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
Old:
It can be a maven-eclipse-tomcat problem or it is related to using Jersey 3 instead of Jersey 2.32. Where should I start checking (besides projects settings: Java Build Path (see screenshot) and Deployment Assembly)?
For example, the logging debug shows:
DEBUG StatusLogger Starting LoggerContext[name=/sdp-api] from configuration at null
DEBUG StatusLogger Starting LoggerContext[name=/sdp-api, org.apache.logging.log4j.core.LoggerContext@72288480] with configuration XmlConfiguration[location=/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml]...
DEBUG StatusLogger Shutdown hook enabled. Registering a new one.
DEBUG StatusLogger Apache Log4j Core 2.14.1 initializing configuration XmlConfiguration[location=/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml]
DEBUG StatusLogger Installed 1 script engine
Warning: Nashorn engine is planned to be removed from a future JDK release
DEBUG StatusLogger Oracle Nashorn version: 11.0.11, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
DEBUG StatusLogger PluginManager 'Core' found 123 plugins
DEBUG StatusLogger PluginManager 'Level' found 0 plugins
DEBUG StatusLogger PluginManager 'Lookup' found 17 plugins
DEBUG StatusLogger Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
TRACE StatusLogger TypeConverterRegistry initializing.
DEBUG StatusLogger PluginManager 'TypeConverter' found 26 plugins
DEBUG StatusLogger PatternLayout$Builder(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
DEBUG StatusLogger Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
DEBUG StatusLogger ConsoleAppender$Builder(target="SYSTEM_OUT", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), name="Console", Configuration(/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml), Filter=null, ={})
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false
DEBUG StatusLogger Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
DEBUG StatusLogger createAppenders(={Console})
DEBUG StatusLogger Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
DEBUG StatusLogger createAppenderRef(ref="Console", level="null", Filter=null)
DEBUG StatusLogger Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
DEBUG StatusLogger createLogger(additivity="null", level="DEBUG", includeLocation="null", ={Console}, ={}, Configuration(/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml), Filter=null)
DEBUG StatusLogger Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
DEBUG StatusLogger createLoggers(={root})
DEBUG StatusLogger Configuration XmlConfiguration[location=/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml] initialized
DEBUG StatusLogger Starting configuration XmlConfiguration[location=/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml]
DEBUG StatusLogger Started configuration XmlConfiguration[location=/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml] OK.
TRACE StatusLogger Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@67b3960b...
TRACE StatusLogger DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
TRACE StatusLogger DefaultConfiguration stopping root LoggerConfig.
TRACE StatusLogger DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
TRACE StatusLogger DefaultConfiguration stopping remaining Appenders.
DEBUG StatusLogger Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG StatusLogger OutputStream closed
DEBUG StatusLogger Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
DEBUG StatusLogger Appender DefaultConsole-1 stopped with status true
TRACE StatusLogger DefaultConfiguration stopped 1 remaining Appenders.
TRACE StatusLogger DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
DEBUG StatusLogger Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@67b3960b OK
TRACE StatusLogger Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector@42805abe
TRACE StatusLogger Reregistering context (1/1): '/sdp-api' org.apache.logging.log4j.core.LoggerContext@72288480
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=StatusLogger'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=ContextSelector'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=Loggers,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=Appenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=AsyncAppenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=AsyncLoggerRingBuffer'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=/sdp-api,component=Loggers,name=*,subtype=RingBuffer'
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=/sdp-api
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=/sdp-api,component=StatusLogger
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=/sdp-api,component=ContextSelector
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=/sdp-api,component=Loggers,name=
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=/sdp-api,component=Appenders,name=Console
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
TRACE StatusLogger Using DummyNanoClock for nanosecond timestamps.
DEBUG StatusLogger LoggerContext[name=/sdp-api, org.apache.logging.log4j.core.LoggerContext@72288480] started OK with configuration XmlConfiguration[location=/path/to/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sdp-api/WEB-INF/classes/log4j2.xml].
DEBUG StatusLogger Log4jServletContextListener ensuring that Log4j starts up properly.
DEBUG StatusLogger Log4jServletFilter initialized.
Solution
Jersey 3.0 is an implementation of Jakarta RESTful Web Services 3.0, which is part of Jakarta EE 9.
This is the first version, which uses the new jakarta.*
package namespace instead of the old namespace javax.*
. Therefore Jersey 3.0 works only with other Jakarta EE 9 technologies and is not compatible with Jakarta EE 8 specifications.
If you wish to use Jersey 3.0, you need to upgrade to Tomcat 10.
Answered By - Piotr P. Karwasz