views:

93

answers:

2

I haven't found a Maven plugin or target that will package my app and deploy it to Glassfish without error. I get this exception:

[ERROR] com.sun.enterprise.admin.cli.CommandException: remote failure: Exception while preparing the app : java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-unit-ref-name [org.us.impl.MyClass/entityManagerFactory] in scope of the module called [man-java-really-stinks-app]. Please verify your application.

This isn't a Spring/Hibernate/EntityManagerFactory/Jpa problem. The app runs fine in the embedded Maven Glassfish container.

I changed packaging to ear in my pom.xml and got this when I deployed to Glassfish

Error during deployment : org.xml.sax.SAXParseException: The content of element type "application" is incomplete, it must match "(icon?,display-name,description?,module+,security-role*)".

IS there a plugin that will take care of the J2EE packaging requirements?

Bonus question: Since the Entities (just POJOS!) and the application need to be packaged differently, is it best to separate these into Maven sub-projects?

+1  A: 

I haven't found a Maven plugin or target that will package my app and deploy it to Glassfish without error.

For the packaging, there is everything you need: the maven-jar-plugin for JARs (including JARs packaging JPA entities), the maven-war-plugin for WARs, the maven-ejb-plugin for EJB-JARs, the maven-ear-plugin for EARs, the maven-rar-plugin for resource adapters.

This isn't a Spring/Hibernate/EntityManagerFactory/Jpa problem. The app runs fine in the embedded Maven Glassfish container.

Well, I'm still tempted to say that there is a JPA configuration problem somewhere anyway, the container is clearly failing at finding a (default?) persistence unit. But since I have no idea of the kind of app you're running (I guess it's a webapp but would like to get confirmation), what your persistence.xml looks like, how you inject the EntityManager, how you configured the database access, how you configured Spring, the version of GlassFish you're running, etc, etc, it will be hard to say anything more.

I changed packaging to ear in my pom.xml and got this when I deployed to Glassfish

That's not that easy. Building an EAR typically involves a multi-modules build, and you are expected to provide a special deployment descriptor. But I'm not convinced you need an EAR packaging and if you can avoid it, don't use it.

IS there a plugin that will take care of the J2EE packaging requirements?

As I said, there are plugins for everything you need, from J2EE to Java EE 6. Just provide the details requested above.

Bonus question: Since the Entities (just POJOS!) and the application need to be packaged differently, is it best to separate these into Maven sub-projects?

Entities and the application do NOT (always) need to be packaged differently, you can package entities directly inside a WAR (I'm extrapolating but I suspect this is your case). I just think you have a configuration problem somewhere, even if the application is running in GF Embedded.

By the way, almost Everything is POJO in Java EE (Entities, Session Beans, Message Driven Beans, etc), but there is no direct consequence on packaging, packaging and POJOness are unrelated.

Pascal Thivent
Thanks, Pascal."Entities and the application do NOT (always) need to be packaged differently, you can package entities directly inside a WAR (I'm extrapolating but I suspect this is your case)." That's good to hear. Most of what I read was steering me down the path of EAR file. What is it that a project does that requires an ear file?As for our project. We have five JPA entities and some fairly simple JAX-RS resources exposed as services.I'll re-inspect the war that is getting created and make sure that I have Maven configured correctly
mocorp
You have to use an EAR when using EJBs. And even this isn't strictly true anymore in Java EE 6, you can deploy EJBs in a WAR (of course, you don't benefit from the classloader isolation offered by EARs but most app don't need that anyway).
Pascal Thivent
A: 

org.us.impl.MyClass had a @PersistenceUnit annotation. The persistince is managed by Spring, but Glassfish takes a sweep of the annotation classes and tries to resolve it itself. You can tell Glassfish to knock it off by adding

metadata-complete="true"

to your web.xml, like so

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                       metadata-complete="true">

Further reading: https://glassfish.dev.java.net/issues/show_bug.cgi?id=4204

mocorp
Thanks for posting your own answer. This is very far away from the original question though.
Pascal Thivent