views:

93

answers:

3

I think, I misunderstood rules of packaging ejb beans in war package.

Goal: I want to use ejb beans in war package.

Scenario: I have some bean in my war:

@Stateless
public class RegistrationServiceBean {

    @PersistenceContext(unitName = "Utopia")
    EntityManager em;

    public RegistrationServiceBean() {}

    @Schedule(hour = "*", minute = "*", second = "*/15")
    public void baseRegistration() {
        System.out.println("call from ejb!!");
    }

    public void saveTempPartner(OasysPartnerTempEntity part) {
        em.persist(part);
        em.flush();
    }
}

It successfully deploying to glassfish server (ogs 3.0.1) :

[#|2010-07-02T16:53:59.728+0300|INFO|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=36;_ThreadName=Thread-1;|Portable JNDI names for EJB RegistrationServiceBean : [java:global/oasys/hydra/RegistrationServiceBean!ua.co.oasys.hydra.beans.RegistrationServiceBean, java:global/oasys/hydra/RegistrationServiceBean]|#]

But when the scheduler is starting I get :

[#|2010-07-02T16:54:20.004+0300|WARNING|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=38;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB RegistrationServiceBean method public void ua.co.oasys.hydra.beans.RegistrationServiceBean.baseRegistration() javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:448) at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467) at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1860) at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3962) at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1667) at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:98) at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2485) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:720) at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200) at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:443) ... 12 more Caused by: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:528) at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:90) at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:718) ... 14 more Caused by: java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768) at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:1171) at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:132) at org.glassfish.weld.services.JCDIServiceImpl._createJCDIInjectionContext(JCDIServiceImpl.java:145) at org.glassfish.weld.services.JCDIServiceImpl.createJCDIInjectionContext(JCDIServiceImpl.java:122) at com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1616) at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:469) ... 16 more |#]

All application packaged in in ear with war inside, it works good if I am deploying ejb in ejb-jar, but is not what I want.

After I removed weld dependency, I got exception during deployment:

com.sun.enterprise.admin.cli.CommandException: remote failure: Exception while loading the app : org.glassfish.deployment.common.DeploymentException: by java.lang.NoClassDefFoundError: ua/co/oasys/hydra/beans/RegistrationServiceBean

It is similar to glassfish bug, but I am not sure .


updates: web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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_3_0.xsd"&gt;
    <display-name>CO UA Partners</display-name>
    <description>CO UA Partners Site</description>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>


    <!--Prime Faces-->
    <context-param>
        <param-name>primefaces.skin</param-name>
        <param-value>sam</param-value>
    </context-param>



    <!--Prime Faces end-->

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>

    <security-role>
        <role-name>manager</role-name>
    </security-role>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Manager Pages</web-resource-name>
            <url-pattern>/faces/partner/manager/*</url-pattern>
            <url-pattern>/partner/manager/*</url-pattern>
            <url-pattern>/partner/*</url-pattern>
            <url-pattern>/faces/partner/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>manager</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <role-name>admin</role-name>
    </security-role>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Admin Pages</web-resource-name>
            <url-pattern>/faces/partner/admin/*</url-pattern>
            <url-pattern>/partner/admin/*</url-pattern>
            <url-pattern>/partner/*</url-pattern>
            <url-pattern>/faces/partner/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>

    <!--roots-->


    <security-role>
        <role-name>rmanager</role-name>
    </security-role>
    <security-role>
        <role-name>radmin</role-name>
    </security-role>
    <security-role>
        <role-name>bookkeper</role-name>
    </security-role>


    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>oasysRealm</realm-name>
        <form-login-config>
            <form-login-page>/faces/login.xhtml</form-login-page>
            <form-error-page>/faces/loginError.xhtml</form-error-page>
        </form-login-config>
    </login-config>



</web-app>

NoClassDefFoundError exception :

[#|2010-07-04T16:16:26.401+0300|SEVERE|oracle-glassfish3.0.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=25;_ThreadName=Thread-1;|Exception while loading the app org.glassfish.deployment.common.DeploymentException: by java.lang.NoClassDefFoundError: ua/co/oasys/hydra/RegistrationServiceBea at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:167) at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125) at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:224) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272) at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224) at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365) at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204) at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166) at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.RuntimeException: by java.lang.NoClassDefFoundError: ua/co/oasys/hydra/RegistrationServiceBea at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:344) at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:314) at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:273) at org.jboss.weld.util.Proxies.createProxyClass(Proxies.java:187) at org.jboss.weld.util.Proxies.createProxyClass(Proxies.java:168) at org.jboss.weld.bean.SessionBean.initProxyClass(SessionBean.java:221) at org.jboss.weld.bean.SessionBean.initialize(SessionBean.java:143) at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:110) at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151) at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:377) at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:165) ... 30 more Caused by: javassist.CannotCompileException: by java.lang.NoClassDefFoundError: ua/co/oasys/hydra/RegistrationServiceBea at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:169) at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:339) ... 40 more Caused by: java.lang.NoClassDefFoundError: ua/co/oasys/hydra/RegistrationServiceBea at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at sun.reflect.GeneratedMethodAccessor196.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javassist.util.proxy.FactoryHelper.toClass2(FactoryHelper.java:181) at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:163) ... 41 more Caused by: java.lang.ClassNotFoundException: ua.co.oasys.hydra.RegistrationServiceBea at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:713) at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:626) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 49 more |#]


Update 2:

If remove/rename beans.xml file ejbs deployed successfully.


Update 3:

oasys.ear

jar xfv ~/Sites/workspace/Intellij_IDEA_9/Oasys/Oasys-ear/target/oasys.ear created: META-INF/ inflated: META-INF/MANIFEST.MF created: lib/ inflated: fenix.jar inflated: hydra.war inflated: javax.inject-1.jar inflated: jboss-interceptor-api-1.1-CR1.jar inflated: jsr250-api-1.0.jar inflated: lib/cdi-api-1.0-CR4.jar inflated: lib/eclipselink-2.1.0-SNAPSHOT.jar inflated: lib/javax.persistence-2.0.0.jar inflated: lib/slf4j-api-1.6.0.jar inflated: lib/slf4j-jdk14-1.6.0.jar inflated: lib/utopia.jar inflated: lib/weld-logger-1.0.0-CR2.jar inflated: META-INF/application.xml
created: META-INF/maven/ created: META-INF/maven/ua.co.oasys/ created: META-INF/maven/ua.co.oasys/oasys-ear/ inflated: META-INF/maven/ua.co.oasys/oasys-ear/pom.xml inflated: META-INF/maven/ua.co.oasys/oasys-ear/pom.properties

hydra.war

jar xfv ~/Sites/workspace/Intellij_IDEA_9/Oasys/Hydra/target/hydra.war created: META-INF/ inflated: META-INF/MANIFEST.MF created: partner/ created: partner/admin/
created: partner/manager/ created: resources/ created: resources/css/
created: resources/css/sam/ created: resources/css/sam/images/ created: resources/layout/ created: resources/security/ created: root/
created: root/admin/ created: root/bookkeeper/ created: root/manager/ created: WEB-INF/
created: WEB-INF/classes/ created: WEB-INF/classes/ua/ created: WEB-INF/classes/ua/co/ created: WEB-INF/classes/ua/co/oasys/
created: WEB-INF/classes/ua/co/oasys/hydra/
created: WEB-INF/classes/ua/co/oasys/hydra/common/ created: WEB-INF/classes/ua/co/oasys/hydra/i18n/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/registration/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/security/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/hydra/ created: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/hydra/i18n/ created: WEB-INF/lib/ inflated: html5.html inflated: index.xhtml inflated: login.xhtml inflated: loginError.xhtml inflated: partner/admin/admin.xhtml inflated: partner/manager/manager.xhtml inflated: partner/partner.xhtml inflated: register.xhtml inflated: resources/css/cssLayout.css inflated: resources/css/default.css inflated: resources/css/master.css inflated: resources/css/sam/images/sprite.png inflated: resources/css/sam/images/ui-bg_flat_0_aaaaaa_40x100.png inflated: resources/css/sam/images/ui-bg_flat_75_ffffff_40x100.png inflated: resources/css/sam/images/ui-bg_glass_55_fbf9ee_1x400.png inflated: resources/css/sam/images/ui-bg_glass_65_ffffff_1x400.png inflated: resources/css/sam/images/ui-bg_glass_75_dadada_1x400.png inflated: resources/css/sam/images/ui-bg_glass_75_e6e6e6_1x400.png inflated: resources/css/sam/images/ui-bg_glass_95_fef1ec_1x400.png inflated: resources/css/sam/images/ui-bg_highlight-soft_75_cccccc_1x100.png inflated: resources/css/sam/images/ui-icons_222222_256x240.png inflated: resources/css/sam/images/ui-icons_2e83ff_256x240.png inflated: resources/css/sam/images/ui-icons_454545_256x240.png inflated: resources/css/sam/images/ui-icons_888888_256x240.png inflated: resources/css/sam/images/ui-icons_cd0a0a_256x240.png inflated: resources/css/sam/skin.css inflated: resources/layout/doublevontent.xhtml inflated: resources/layout/header.xhtml inflated: resources/layout/masterLayout.xhtml inflated: resources/prime-themes/vader/skin.css inflated: resources/security/loginPanel.xhtml inflated: root/admin/radmin.xhtml inflated: root/bookkeeper/rbookkeeper.xhtml inflated: root/manager/rmanager.xhtml inflated: WEB-INF/beans.xml inflated: WEB-INF/classes/ua/co/oasys/hydra/common/SkinBean.class inflated: WEB-INF/classes/ua/co/oasys/hydra/i18n/messages.properties inflated: WEB-INF/classes/ua/co/oasys/hydra/i18n/messages_en_US.properties inflated: WEB-INF/classes/ua/co/oasys/hydra/i18n/messages_ru_RU.properties inflated: WEB-INF/classes/ua/co/oasys/hydra/i18n/messages_uk_UA.properties inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/CustomCharacterEncodingFilter.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/Messenger.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/registration/TempReg.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/security/LogOutActionListener.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/security/LogoutServlet.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/security/RulesBean.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/security/SecurityBacking.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/security/UserBean.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/security/UserManager.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/hydra/i18n/Messages.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/hydra/i18n/Utf8ResourceBundle$1.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/hydra/i18n/Utf8ResourceBundle$Utf8PropertyResourceBundle.class inflated: WEB-INF/classes/ua/co/oasys/hydra/mb/ua/co/oasys/hydra/i18n/Utf8ResourceBundle.class inflated: WEB-INF/classes/ua/co/oasys/hydra/RegistrationServiceBea.class inflated: WEB-INF/faces-config.xml

inflated: WEB-INF/lib/primefaces-2.1.RC1-SNAPSHOT.jar inflated: WEB-INF/sun-web.xml inflated: WEB-INF/web.xml created: META-INF/maven/ created: META-INF/maven/ua.co.oasys/ created: META-INF/maven/ua.co.oasys/hydra/ inflated: META-INF/maven/ua.co.oasys/hydra/pom.xml inflated: META-INF/maven/ua.co.oasys/hydra/pom.properties


  • Q1: is it passable to use ejb beans packaged in war (specification sad that is true)?
  • Q2: should I describe some configuration by ejb-jar.xml ?
  • Q3: what could be a cause of a problem?
A: 

EJBs packaged in a WAR are using the web / lite profile of EE6. As far as I know, timers and some other features are not supported in this profile. So if you want to use timers you would have to package your ejbs in the traditional ejbjar + war + ear way.

I could not find a reference for the web profile, this is the closest to a comparison: http://www.theserverside.com/news/1321142/Part-Three-New-Features-in-EJB-31

Edit: I stand corrected, war packaging is actually described in jsr 318, EJB 3.1. Since I could not find any restrictions on available features in that section of the spec, timers should also work in an ejb packaged in a war.

Jörn Horstmann
This is **incorrect**. When packaged in a WAR (vs EAR), only the class loading of EJBs is different (see the section **20.4 Enterprise Beans Packaged in a .war** of the specification for full details). But using a WAR packaging and using a web profile implementation are just two **unrelated** things. I'm using a WAR packaging with the "full" implementation and timers just work.
Pascal Thivent
A: 

It is similar to glassfish bug, but I am not sure .

Hard to say, especially since you didn't provide the stacktrace for the NoClassDefFoundError, but the scenario seems different anyway.

Q1: is it passable to use ejb beans packaged in war (specification sad that is true)?

Definitely. You can either put EJB classes in WEB-INF/classes or package them as EJB-JAR and put them in WEB-INF/lib. I have several demo applications doing this.

Q2: should I describe some configuration by ejb-jar.xml ?

No, nothing forces you to do so.

Q3: what could be a cause of a problem?

The problem is that I couldn't reproduce the problem... I've deployed your EJB in a webapp with [ejb, jpa, web, webservices, weld] engines enabled (I just modified it to insert an Entity of mine in the scheduled method) and it just works. Tested with an up-to-date version of GlassFish 3.0.1. So I suspect a mistake or configuration problem on your side.

Just in case, can you provide the output of jar xfv yourapp.war (and also show your web.xml)?

Pascal Thivent
I crate addition question with project link- http://stackoverflow.com/questions/3175458/cdi-with-ejb-3-1-weld-logger-on-glassfish-v3-0-1
kislo_metal
A: 

See: http://stackoverflow.com/questions/3175458/cdi-with-ejb-3-1-weld-logger-on-glassfish-v3-0-1 There I Describe step to reproduce this issues.

As I understand - there is no possibility to use CDI & EJB in one web module packaged in ear archive together and deployed t glassfish 3.0.1.

Current design is to separate ejb and war module - at list it forks for me.

kislo_metal
How does this answer **a single bit** of the above questions? Posting a link (and accepting it) to another question doesn't answer anything but only suggest that the new question is a duplicate. This is really a poor practice (and doesn't motivate me at all to help further). Good luck.
Pascal Thivent
sorry, I correct my answer.
kislo_metal