Skip to main content

Problem deploying same SSB class in different apps on Glassfish v3

12 replies [Last post]
icordoba
Offline
Joined: 2005-02-01

Hi there,
I need to deploy multiple apps in the same glassfish instance (v3) previously working on JBoss.
I am having the following naming exception:

Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override

Previous deployed app deploys a Stateless Session Bean with the same class name. New EJB3.1 Global JNDI naming works ok but "Glassfish-specific (Non-portable) JNDI" gives previous conflict as it is not application dependent (in my case, that JNDI name is [com.servengine.user.UserManager#com.servengine.user.UserManager, com.servengine.user.UserManager]|#] which is the same for all apps.

Any idea on how can I disable Glassfish specific JNDI naming or make it add some application name prefix, like in EJB 3.1 Global JNDI?

thanks,
Ignacio

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ksak
Offline
Joined: 2005-05-20

Hi Xavier,

Right, if you want the code in the .war to act as a client of an EJB component that exposes a Remote and/or Local interface, then just put the interfaces in the .war.

--ken

xcallejas
Offline
Joined: 2009-07-29

Ken,

I can't make a ejb package containing only interfaces, right? why? (I would like to include it in both: .war and implementations ejb .jar, to share the interfaces code).

Thank you and sorry for ask such newbe things.

rgds.
xavier

icordoba
Offline
Joined: 2005-02-01

You can have a look at EJB3.1 packaging specs, specially the ones related to packaging EJBs inside a war file/directory.
You can package all your EJBs (interfaces and beans) in a jar along with persistence.xml file, client code (managed classes/struts actions/...) in another jar. Both can now reside in /WEB-INF/lib/ of war.
Of course you need Glassfish v3 to deploy this way... not too many App servers currently support this.

xcallejas
Offline
Joined: 2009-07-29

Thank you.

I will have a look to EJB3.1 specs.

But I will try to put all into a EAR.

rgds.
xavier

xcallejas
Offline
Joined: 2009-07-29

Hi,

I have the same problem, I have a EJB that I want to share, in the same server instance, with other two web apps., and they are NOT part of a/the same EAR. I deploy first the EJB, then I proceed to deploy wep_app_1.war, ups! "... javax.naming.NameAlreadyBoundException ..." .

(web_app_1.war and web_app_1.war has myEJB.jar packed inside).

It seems that when Glassfish 3 find EJB package inside a .war it tries to deploy it.

Do you found a solution?

(this is not a problem in Glassfish 2.1, does anyone knows if EJB 3.1 or Glassfish force to use a EAR??? to have access to beans???)

Message was edited by: xcallejas

ksak
Offline
Joined: 2005-05-20

EJB 3.1 removes the restriction that EJB components must be packaged in an ejb-jar. If you don't want the .war to define its own EJB component, then don't package the bean class (which contains the @Stateless or @Stateful annotation) anywhere in the .war.

If the .war should only contain code that acts as a *caller* of an EJB component, then make sure to only package the interfaces and supporting classes for the caller, not the EJB component implementation.

xcallejas
Offline
Joined: 2009-07-29

Hi Ksak,

Please tell me if I understood you well:

Actually I have in the same EJB package the interfaces (remote and local) and its implementation, but I need to separate the interfaces and implementation in diferents packages, and include only the interfaces package in the .WAR?

Thank you in advance.

rgds.
xavier

icordoba
Offline
Joined: 2005-02-01

Hello,
my problem was solved by placing only persistence.xml in the EJB jar file inside /WEB-INF/lib/
To change the specific glassfish JNDI names I just had to create a sun-ejb-jar.xml in /WEB-INF/
No need for ejb-jar.xml, just sun-ejb.jar.xml works if you use the standard EJB ids. I can deploy multiple instances of the same EJBs in different webapps this way, and no need for .ear packaging of course. Just wars. Love these new EJB 3.1 specs.

ksak
Offline
Joined: 2005-05-20

Hi Ignacio,

We don't have a way to disable the Glassfish-specific default names, so the best approach is to package a sun-ejb-jar.xml with the second, third, etc. application that sets the to something unique.

--ken

icordoba
Offline
Joined: 2005-02-01

Hello,
thanks a lot for your reply.

I've tried with only sun-ejb.jar.xml and also with both that and ejb-jar.xml:

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0" xmlns="http://java.sun.com/xml/ns/javaee">
myApp


Se necesita por el puto nombre específico de Glassfish
UserManager
com.servengine.user.UserManagerLocal
com.servengine.user.UserManager
com.servengine.user.UserManagerBean
Stateless






UserManager
myApp/UserManager



I still get:
[[#|2010-01-26T19:23:51.387+0100|INFO|glassfishv3.0|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=25;_ThreadName=Thread-1;|Glassfish-specific (Non-portable) JNDI names for EJB UserManager : [com.servengine.user.UserManager#com.servengine.user.UserManager, com.servengine.user.UserManager]|#]

And keeps conflict with the other apps.

Am I missing something? Don't know if I need any other descriptor... (I am using new EJB 3.1 option to deploy EJBs in /WEB-INF/lib... hope this is not causing Glassfish to ignore sun-ejb-jar.xml )

Thanks for any help... I need to deploy multiple apps with same classes and just can't launch a JVM with a Glassfish domain for each. Oh God... don't want to go back to JBoss!! :-)

ksak
Offline
Joined: 2005-05-20

Did you put it in WEB-INF? In the .war, it doesn't go in META-INF.

icordoba
Offline
Joined: 2005-02-01

mmmm... I pack them in META-INF/ in a .jar file containing all EJBs, which I deploy in /WEB-INF/lib
I didn't use any deployment descriptor anymore... I'll try placing them in /WEB-INF
Thanks a lot.