0

I have created a Liferay Blade "rest" module with the sample code that is provided with that template. I am trying to access the sample code's /greetings endpoint at: http://localhost:8080/o/greetings

The error I'm receiving appears to be common and well-documented because in Java 11, JAXB was completely removed from the JDK altogether:

JAXBException occurred : Implementation of JAXB-API has not been found on module path or classpath.. com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.4

The module builds and deploys into Liferay 7.2 with gradle, with no errors and the suggested solutions are not resolving the error (obviously).

Full disclosure, I am not a Java developer and therefore clearly lack a very basic understanding of Java, which could be contributing to the problem.

I have tried including the suggested dependencies to my gradle.build file:

compile('javax.xml.bind:jaxb-api:2.3.0')
compile('javax.activation:activation:1.1')
compile('org.glassfish.jaxb:jaxb-runtime:2.3.0')

I have also tried downloading and deploying the jar files for the above dependencies into Liferay 7.2. No luck.

My gradle.build file:

dependencies {
    compileOnly group: "javax.ws.rs", name: "javax.ws.rs-api", version: "2.1"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
    compileOnly group: "org.osgi", name: "org.osgi.service.jaxrs", version: "1.0.0"
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "4.4.0"

}

The sample class file:

package some.random.super.long.folder.path;

import java.util.Collections;
import java.util.Set;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.UserLocalServiceUtil;
import com.liferay.portal.kernel.util.PropsUtil;

import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;

/**
 * @author andrew
 */
@Component(
    property = {
        JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE + "=/greetings",
        JaxrsWhiteboardConstants.JAX_RS_NAME + "=Greetings.Rest"
    },
    service = Application.class
)
public class DiningRestServiceApplication extends Application {

    public Set<Object> getSingletons() {
        return Collections.<Object>singleton(this);
    }

    @GET
    @Produces("text/plain")
    public String working() {
        return "It works!";
    }

    @GET
    @Path("/morning")
    @Produces("text/plain")
    public String hello() {
        return "Good morning!";
    }

    @GET
    @Path("/morning/{name}")
    @Produces("text/plain")
    public String morning(
        @PathParam("name") String name,
        @QueryParam("drink") String drink) {

        String greeting = "Good Morning " + name;

        if (drink != null) {
            greeting += ". Would you like some " + drink + "?";
        }

        return greeting;
    }

}

The expected result I am after is to receive the sample messages at the specified sample's endpoints.

Any help from this wonderful community would be greatly appreciated!

UPDATE

I switched to Java 9 JDK on my machine. I'm still experiencing the aforementioned error message.

user2305363
  • 157
  • 2
  • 15

3 Answers3

0

Jorge Diaz of the Liferay community just responded in the Liferay forum stating that this looks like an existing bug that is currently being worked on.

https://issues.liferay.com/browse/LPS-92576 https://issues.liferay.com/browse/LPS-97968

Regardless, I confirmed that the combination of Liferay and Java 9 and 11 are not playing nicely with JAXB by downgrading to Java 8, which worked.

user2305363
  • 157
  • 2
  • 15
0

Liferay ships an implementation for JAXB in the product. We just need to configure the JVM to look for it instead of trying to look for the default old one.

Just setting the property javax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory should do it. You should be able to set it on your environment or executable for the JVM that starts Liferay.

It should be set by default if later Liferay versions.

csierra
  • 1,010
  • 10
  • 8
0

The solution provided by Carlos Sierra works. Add

-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory 

to the list of VM arguments to point to ContextFactory implementation provided by Liferay.

Environment: openjdk version "11.0.5" 2019-10-15 with Liferay DXP 7.2.10 GA1 SP 2 (dxp-2-7210)