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.