Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jetty-maven-plugin:11.0.0 not picking up @WebServlet #5964

Closed
wh81752 opened this issue Feb 10, 2021 · 4 comments
Closed

jetty-maven-plugin:11.0.0 not picking up @WebServlet #5964

wh81752 opened this issue Feb 10, 2021 · 4 comments

Comments

@wh81752
Copy link

wh81752 commented Feb 10, 2021

Jetty version
11.0.0

Java version

$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03)
OpenJDK 64-Bit Server VM GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03, mixed mode, sharing)

OS type/version

$ uname -a
Darwin MacBook-Pro.fritz.box 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

Description
I have a (simple) Servlet 3.0 servlet, i.e. @WebServlet instead of web.xml. I use jetty-maven-plugin to test my servlet during development.

This works as expected using Jetty version 9.4.36.v20210114 and 10.0.0. It does not work any longer using Jetty 11.0.0. It looks like @WebServlet is not picked up:

> mvn clean package jetty:run
[..]
[INFO] --- jetty-maven-plugin:11.0.0:run (default-cli) @ cxf-spring ---
[INFO] Configuring Jetty for project: CXF Spring Demo
[INFO] Classes = /Users/geronimo1/ws/cxf-samples/java_first_spring_support/target/classes
[INFO] Context path = /
[INFO] Tmp directory = /Users/geronimo1/ws/cxf-samples/java_first_spring_support/target/tmp
[INFO] web.xml file = null
[INFO] Webapp directory = /Users/geronimo1/ws/cxf-samples/java_first_spring_support/src/main/webapp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] jetty-11.0.0; built: 2020-12-02T21:37:29.286Z; git: 432f896d7a4555fcc81f38108757ea0aca8788e6; jvm 11.0.8+10-jvmci-20.2-b03
[WARNING] javax.activation.ActivationDataFlavor scanned from multiple locations: jar:file:///Users/geronimo1/.m2/repository/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar!/javax/activation/ActivationDataFlavor.class, jar:file:///Users/geronimo1/.m2/repository/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar!/javax/activation/ActivationDataFlavor.class
[... many further warnings, all (?) related to jakarta.activation-api ..]
Feb 10, 2021 10:56:31 PM org.eclipse.jetty.util.log.Log initialized
INFO: Logging initialized @8292ms to org.eclipse.jetty.util.log.Slf4jLog
[INFO] Session workerName=node0
[INFO] Started o.e.j.m.p.MavenWebAppContext@52035328{/,[file:///Users/geronimo1/ws/cxf-samples/java_first_spring_support/src/main/webapp/],AVAILABLE}{file:///Users/geronimo1/ws/cxf-samples/java_first_spring_support/src/main/webapp/}
[INFO] Started ServerConnector@2ec23ec3{HTTP/1.1, (http/1.1)}{0.0.0.0:9002}
[INFO] Started Server@2d3bb944{STARTING}[11.0.0,sto=0] @8444ms
[INFO] Scan interval ms = 1000

The jetty-maven-plugin is really basic:

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
<!--                <version>9.4.36.v20210114</version>-->
<!--                <version>10.0.0</version>-->
                <version>11.0.0</version>
                <configuration>
                    <scan>1000</scan>       <!-- changed from 10.x to 11.x for unkown reason -->
                    <httpConnector>
                        <port>9002</port>
                    </httpConnector>
                </configuration>
            </plugin>
@wh81752
Copy link
Author

wh81752 commented Feb 10, 2021

A reference project demonstrating the problem is available here: https://github.com/wh81752/cxf-spring-servlet/tree/servlet-3.0 => The problem is shown when changing fom version 10.0.0 to 11.0.0

@joakime
Copy link
Contributor

joakime commented Feb 10, 2021

Jetty 11 is based on Jakarta Servlet 5.0

That means you have to use the jakarta.servlet.annotation.WebServlet annotation (look at the package namespace)

https://github.com/eclipse-ee4j/servlet-api/blob/5.0.0-RELEASE/api/src/main/java/jakarta/servlet/annotation/WebServlet.java

There is no backward compatibility with javax.servlet.annotation.WebServlet (notice the package namespace difference?)

The old javax.servlet namespace is dead. There will never be another update or release under that namespace.
Oracle got rid of the entire Java EE project, and moved it over to the Eclipse Foundation a few year ago.
The old namespaces starting with "javax" are not allowed to be used by the Eclipse Foundation (so says Oracle lawyers) going forward.
So that means we got the new namespace starting with jakarta.* to work with.

@wh81752
Copy link
Author

wh81752 commented Feb 11, 2021

That means you have to use the jakarta.servlet.annotation.WebServlet annotation (look at the package namespace)

Ahhhh, the namespace of course. Didn't think one second on that, my Intellij even hides all import statements.

The old namespaces starting with "javax" are not allowed to be used by the Eclipse Foundation (so says Oracle lawyers) going forward.

I wonder whether it would also be disallowed to scan for the presence of javax.* annotations and log warnings about being ignored?

So that means we got the new namespace starting with jakarta.* to work with.
All fine if that jakarta.* namespace stays forever.

Anyway, thx for your swift & helpfull response and let's close this issue.

@wh81752 wh81752 closed this as completed Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants