I am trying to write a webapp that will run on multiple types of app server. I wrote one that worked on Wildfly - no web.xml, but would not deploy on TomEE so I looked for tutorials.
One tutorial I found said including all the jersey jars in WEB-INF/lib would work. I downloaded jersey 2.34.
I have tried that, and given a web.xml to see if that helps portability.
The app loads in TomEE but only the static index.html works. The jax-rs service 404s.
It works in Wildfly.
What else do I need to get it going in plain Tomcat, or TomEE? Does it still need an application class despite the init-param?
Is there an app-server neutral means of doing away with the web.xml file?
One other weird thing happened. If I compile with jdk15 (or 16) TomEE fails to load it saying the class file format cannot be read, despite the fact it is certainly running with the same jdk as it was built with. If I drop back to compiling and running with jdk8 the problem goes away. I'm guessing this is something to do with modules but the stack traces just say the class file cannot be read. Why is TomEE having that problem? Does it need more args in the java command?
Here is web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>grazingapp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>x.y.grazingapp.services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
Here is the list of files in the war:
grazingapp/index.html
grazingapp/META-INF/MANIFEST.MF
grazingapp/WEB-INF/classes/x/y/grazingapp/services/Graze.class
grazingapp/WEB-INF/lib/aopalliance-repackaged-2.6.1.jar
grazingapp/WEB-INF/lib/hk2-api-2.6.1.jar
grazingapp/WEB-INF/lib/hk2-locator-2.6.1.jar
grazingapp/WEB-INF/lib/hk2-utils-2.6.1.jar
grazingapp/WEB-INF/lib/jakarta.activation-api-1.2.2.jar
grazingapp/WEB-INF/lib/jakarta.annotation-api-1.3.5.jar
grazingapp/WEB-INF/lib/jakarta.inject-2.6.1.jar
grazingapp/WEB-INF/lib/jakarta.json-1.1.6-module.jar
grazingapp/WEB-INF/lib/jakarta.json-1.1.6.jar
grazingapp/WEB-INF/lib/jakarta.json-api-1.1.6.jar
grazingapp/WEB-INF/lib/jakarta.json.bind-api-1.0.2.jar
grazingapp/WEB-INF/lib/jakarta.persistence-api-2.2.3.jar
grazingapp/WEB-INF/lib/jakarta.servlet-api-4.0.3.jar
grazingapp/WEB-INF/lib/jakarta.validation-api-2.0.2.jar
grazingapp/WEB-INF/lib/jakarta.ws.rs-api-2.1.6-sources.jar
grazingapp/WEB-INF/lib/jakarta.ws.rs-api-2.1.6.jar
grazingapp/WEB-INF/lib/jakarta.xml.bind-api-2.3.3.jar
grazingapp/WEB-INF/lib/javassist-3.25.0-GA.jar
grazingapp/WEB-INF/lib/jersey-client.jar
grazingapp/WEB-INF/lib/jersey-common.jar
grazingapp/WEB-INF/lib/jersey-container-servlet-core.jar
grazingapp/WEB-INF/lib/jersey-container-servlet.jar
grazingapp/WEB-INF/lib/jersey-hk2.jar
grazingapp/WEB-INF/lib/jersey-media-jaxb.jar
grazingapp/WEB-INF/lib/jersey-media-json-binding.jar
grazingapp/WEB-INF/lib/jersey-media-sse.jar
grazingapp/WEB-INF/lib/jersey-server.jar
grazingapp/WEB-INF/lib/org.osgi.core-6.0.0.jar
grazingapp/WEB-INF/lib/osgi-resource-locator-1.0.3.jar
grazingapp/WEB-INF/lib/yasson-1.0.6.jar
grazingapp/WEB-INF/web.xml
The service source code:
package x.y.grazingapp.services;
import javax.ws.rs.*;
@Path("/graze")
public class Graze {
@GET
@Path("/test")
@Produces("text/plain")
public String test() {
return "Hello, world.";
}
}