7

I've developed a Jersey API which returns either XML or JSON (depending on the request header). When deployed on my Windows 2012 server (Tomcat), it works no problem.

When I deploy (after compiling it on Ubuntu) to an Ubuntu machine in AWS (Glassfish), I get the following errors when I request JSON:

The server encountered an internal error that prevented it from fulfilling this request.

exception javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

root cause org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

root cause java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

No errors when I request XML.

I was originally using moxy for JSON serialization, but then started using Jackson.

Any ideas why it would work on one server and not another? Thanks

onefootswill
  • 3,707
  • 6
  • 47
  • 101
  • 1
    Might be a bug of Glassfish. Please refer to [this page](https://stackoverflow.com/questions/33722764/glassfish-error-when-producing-json). – Kohei TAMURA Jun 17 '17 at 13:21
  • @KoheiTAMURA Yeah I saw that. I figured they must have fixed it by now. Apparently not ... – onefootswill Jun 18 '17 at 09:34
  • What if you put all your Jersey related dependencies as "provided"? Remember that Tomcat has no Jersey jars in it, so there is no conflict. But Glassfish _does_ have Jersey. So your project jars might conflict. So you should exclude them from the deployment when deploying to Glassfish, and just use the ones provided by Glassfish. – Paul Samsotha Sep 05 '17 at 03:43
  • @peeskillet I gave it a shot and added a scope element to the dependency for the moxy package with a value of "provided". I still get the same error. – onefootswill Sep 05 '17 at 08:46
  • 1
    Can you please update question with glassfish version? Seems to be a glassfish bug, see the comment from `sentonimo` [here](https://github.com/javaee/glassfish/issues/21141) – Rishikesh Darandale Sep 06 '17 at 13:52

1 Answers1

0

Finally got this working. First, use Tomcat, not Glassfish.

Then, add a new dependency:

<dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
</dependency>

I also upgraded Jersey version to 2.26, but I don't think that made the difference. Just adding that for completeness (as it did happen).

I don't understand the reason it works. I always thought Java ran the same on Windows and Linux. But hey, I'm just a dumb .NET guy.

Hope this helps others who find themselves in a pit of helplessness on this issue as I did.

onefootswill
  • 3,707
  • 6
  • 47
  • 101