0

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.";
    }
}
  • Which version of TomEE are you using? – Piotr P. Karwasz Jun 25 '21 at 12:43
  • Wildfly 23.0.2, TomEE =9.0.0-M7, which seems to have Tomcat 10.0.4 in it. – David Taylor Jun 27 '21 at 09:39
  • Try TomEE 8.0: TomEE 9.0 is a Jakarta EE 9 server, which is incompatible with previous releases. Wildfly 23 is a Java/Jakarta EE 8 server. – Piotr P. Karwasz Jun 27 '21 at 10:13
  • Thankyou @Piotr. I cannot give you credit for answering my question - nothing shows up in your comments to allow me to mark them as an answer. – David Taylor Jun 28 '21 at 00:45
  • Another tip would be write your code to the Jakarta EE RESTful Web Services Spec and not to Jersey. Then it should run on any Jakarta EE container. – James R. Perkins Jun 28 '21 at 15:08
  • I'm trying to make it independent of container - that's why I'm testing with both TomEE and Wildfly. It's mostly working but RESTEasy and Jersey return different things in their UriInfo implementations which is messing up my auth filter. The only thing they have in common is the URI segment list. The matched resources are different as is the relative path. It's very difficult to find a guide on doing this without maven and one of the implementations but of course all you need is the jax-rs-api jar and a java compiler. You wouldn't know that looking at the tutorials out there. – David Taylor Jun 30 '21 at 11:08

0 Answers0