I have a problem when trying to return an object defined in an external .jar from a Java EE 6 Web service.
The Web service looks like the following:
@Stateless
@Path("book")
@Produces({"application/json", "application/xml"})
@Consumes({"application/json", "application/xml"})
public class NewWebService {
@PersistenceContext(unitName = "EnterpriseApplication3-warPU")
private EntityManager em;
@GET
public List<Foo> getBookTitle() {
Query query = em.createNamedQuery("Foo.findAll");
List<Foo> foo = query.getResultList();
return foo;
}
}
When I define the "Foo" class in the same .jar File as the Web service everything works fine. However, I'd like to define "Foo" in an .jar of it's own, as "Foo" is also a JPA bean, and as different components of the application (packaged as .ear) need to be able to access "Foo".
When defining "Foo" in another .jar file (that is packages in the same .ear) Glassfish returns the following error message:
javax.ws.rs.WebApplicationException: javax.xml.bind.JAXBException: class org.example.entity.Foo nor any of its super class is known to this context.
Any hints on how I can workaround this error? "Foo" is a standard JPA bean with the "@XmlRootElement" annotation.