Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7.2 with JAX-RS/JAXB and JDK 11/9 Issue
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. Apparently JAXB was completely removed from the Java 11 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 (mostly the same) are not resolving the error.
Full disclosure, I am not a Java developer and therefore clearly lack a very basic understanding of Java, which could be a major contributer 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"
compileOnly('javax.xml.bind:jaxb-api:2.3.0')
compileOnly('javax.activation:activation:1.1')
compileOnly('org.glassfish.jaxb:jaxb-runtime:2.3.0')
}
The sample class file:
package some.random.super.long.folder.path.application;
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 community would be greatly appreciated!
**UPDATE**
I switched to Java 9 JDK on my machine. I'm still experiencing the aforementioned error message.
The error I'm receiving appears to be common and well-documented. Apparently JAXB was completely removed from the Java 11 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 (mostly the same) are not resolving the error.
Full disclosure, I am not a Java developer and therefore clearly lack a very basic understanding of Java, which could be a major contributer 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"
compileOnly('javax.xml.bind:jaxb-api:2.3.0')
compileOnly('javax.activation:activation:1.1')
compileOnly('org.glassfish.jaxb:jaxb-runtime:2.3.0')
}
The sample class file:
package some.random.super.long.folder.path.application;
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 community would be greatly appreciated!
**UPDATE**
I switched to Java 9 JDK on my machine. I'm still experiencing the aforementioned error message.
Hi Andrew,
I think this is a bug, see following LPS tickets:It seems they are working on them, as last comment on them was 1 hour ago
I think this is a bug, see following LPS tickets:It seems they are working on them, as last comment on them was 1 hour ago
Thank you, Jorge! Glad to hear they're working on it.
I ended up downgrading JAVA to 8, and as expected, there are no JAXB errors.
I ended up downgrading JAVA to 8, and as expected, there are no JAXB errors.