No luck getting embedded deployment to work
myawn Nov 1, 2005 10:44 AMI've tried several different variations on the code shown in the tutorials (deploy by resource, deploy by directory) and I can't get my classes to deploy in an embedded fashion.
I did try packing the classes into a EJB3 jar and deploying them in the application server, and doing so gave me some useful diagnostics (deployment failures) that helped me debug the classes. I was hoping that once they deployed cleanly in the AS, they would also deploy embedded, but it seems my embedded problem must be something different.
One thing I'm doing which is different than any of the examples is I am not packaging the classes (no .jar, .ejb3, or .ear is built); I'm trying to just run out of the directory hierarchy within an Eclipse environment. This leads to one question, which is where should persistence.xml go in this case? I found that I was getting NullPointerExceptions from EJBStandaloneDeployer if I just put the persistence.xml in with the classes. I looked at the source for that class and noticed that the META-INF directory is hard-coded in the persistence.xml lookup. So I placed persistence.xml within a META-INF directory within the resources directory, and the exception went away -- so I think the file is being found now.
I've gone through a lot of permulations of this, but here is what I'm currently using as my 'main' entry point:
/** Test class for EJB 3.0 beans. */ public class EJB30Main { public static void main(String[] args) throws Exception { System.out.println("main loading deployer"); EJB3StandaloneBootstrap.boot(null); EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer(); try { URL wsdldir = new URL("file:///C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/bin/com/kenai/examine/wsdl"); URL resdir = new URL("file:///C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/resources"); deployer.getDeployDirs().add(wsdldir); deployer.getDeployDirs().add(resdir); System.out.println("Deploy dirs " + deployer.getDeployDirs()); deployer.setJndiProperties(getInitialContextProperties()); deployer.create(); deployer.start(); System.out.println("deployer running"); } catch (Exception e) { e.printStackTrace(); deployer.stop(); deployer.destroy(); } WSDLMgr mgr = WSDLMgr.getInstance(); String urlLoc = "http://keithsvr1/UnitTestWS1/Service1.asmx?wsdl"; String wsdlName = "j2eePersistenceTest"; WSDL wsdl = mgr.create(wsdlName, urlLoc); System.out.println("Created " + wsdl.getName() + " " + wsdl.getID()); System.out.println("Stopping and destroying deployer"); deployer.stop(); deployer.destroy(); System.out.println("Normal finish"); } private static Hashtable getInitialContextProperties() { Hashtable<String,String> props = new Hashtable<String,String>(); props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory"); props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); return props; } }
And here is what is currently in persistence.xml
<entity-manager> <name>manager1</name> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/DefaultDS</jta-data-source> <class>com.kenai.examine.wsdl.WSDL</class> <class>com.kenai.examine.database.SharedDBInfo</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> </properties> </entity-manager>
(I've tried with and without the class names, makes no difference).
When I attempt to run the main, here's all I get:
main loading deployer WARN 01-11 07:33:43,568 (XsdBinder.java:bindGlobalGroup:1097) -NOT HANDLED WILDCARD IN GLOBAL MODEL GROUP Deploy dirs [file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/bin/com/kenai/examine/wsdl, file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/resources] deployer running Exception in thread "main" java.lang.NullPointerException at com.kenai.examine.wsdl.WSDLMgr.create(WSDLMgr.java:269) at com.kenai.examine.wsdl.WSDLMgr.create(WSDLMgr.java:218) at com.kenai.examine.wsdl.EJB30Main.main(EJB30Main.java:69)
Within WSDLMgr, I have the following declaration of the EntityManager
@PersistenceContext(name="manager1") public void setEntityManager(EntityManager em) { System.out.println("EM injected"); this.em = em; }
And the line that fails is a call to em.persist(wsdl) -- so the null pointer, plus the lack of output from the method above, show that we aren't ever injecting the entity manager reference.
The WSDLMgr class is annotated as a Stateless Session Bean. Instead of calling getInstance() on it, I also tried making an @EJB reference within the main class (which I think it the preferred way to do it) -- but then that reference is never injected, so I don't even get as far as I did before.
Can anyone point out what I'm doing wrong here? Thanks!
Mike