how to set specific ejb jndi names in jboss 7.1.1 - jboss

my web application contains a few 2.x stateful and stateless session ejbs. but unlike previous jboss versions (as well as other major app servers), i am unable to specify an ejb jndi name in jboss 7.1.1. i have followed their docs by eliminating jboss.xml in favor of jboss-ejb3.xml, as well as starting the app server in full profile mode.
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1"
impl-version="2.0">
<enterprise-beans>
<session>
<ejb-name>MyEJB</ejb-name>
<jndi-name>MyEJB_JNDI_NAME</jndi-name>
</session>
</enterprise-beans>
</jboss:ejb-jar>
however, the jndi-name in jboss-ejb3.xml is not taking hold, preventing me from setting my own custom ejb jndi name. does anyone know how to do this right?

<jndi-name> is no longer supported in JBoss AS 7. From this JIRA:
In AS7 we no longer support binding to custom JNDI names for EJBs. So
the beans are always bound to the spec mandated java:global, java:app
and java:module namespaces. The <jndi-name> for the session bean
element is no longer supported.

Related

What to put into jta-data-source of persistence.xml that works on all vendors?

Similar to What to put into jta-data-source of persistence.xml? and How to map jpa datasources in WildFly?
However, I am asking for something that would work on all vendors or at least WildFly, Glassfish/Payara, WebSphere Application Server classic, WebSphere Application Server Liberty, TomEE. I am not looking for something that works in a Java SE Unit test.
So far I found that java:comp/env/jdbc/xxx works in WebSphere Application Server and TomEE. There's a mapping exercise (which is expected) to get it working but I cannot get the same to work on GlassFish/Payara and JBoss/WildFly.
More specifically I do not wish to use default data source because for my scenario I am actually working on two different data sources. E.g. for reference data and another for transactional.
If all of the app servers you work with are Java EE 7 compliant, you can use the default data source, which is required per EE7 spec to be available at:
java:comp/DefaultDataSource
The app server you run on ought to let you customize the configuration of the DefaultDataSource.
Since I'm familiar with WebSphere Liberty, I can point you to this doc for default data sources on Liberty:
Configuring a default data source
If you are using WebSphere traditional, as of v9.0 it supports Java EE 7, and has a default data source available out of the box (under the spec mandated JNDI name).
If you want to use the same JNDI name that works on all servers, it's best to use resource references, as explained in What is resource-ref in web.xml used for?
Basically, you would define an arbitrary JNDI name (ideally without any java:comp prefix or similar, just something like "myDatasource") and then map it to the concrete JNDI name provided by the target server.You would need to define a server-specific descriptor for each server with the mapping the if the server cannot use the JNDI directly (e.g. glassfish-web.xml for GlassFish/Payara, jboss-web.xml for WildFly, ibm-web-bnd.xml for WebSphere Classic and Liberty). TomEE seems to support references without any prefix, so it should be able to configure a datasource without any additional mapping if you choose a name without a prefix.

overriding JNDI names in JBoss EJB3.1

We're using Maven and Artifactory, and therefore our ear files have names like
our-project-ear-0.0.1-20151215.151526-3.ear.
So JNDI names for our EJBs have names like
java:global/our-project-ear/our-project-ejb/AnEjbJar!com.acme.ourproject.SomeEjb.
These names are not just ugly and complex, they also embed temporary suffixes added by Maven/Artifactory.
I thought we could simplify the names via the JBoss-specific #RemoteHomeBinding annotation, but I do not find this annotation in EAP 6.3. Is there still a way to do this? If not, how can I control the JNDI name under which my EJBs are published?
Figured it out myself. The #RemoteBinding, #LocalBinding, #RemoteHomeBinding and #LocalHomeBinding annotations have been phased out in AS7.x. A version of the JBoss instructions for migrating from AS5/6 to AS7 (not the current one) states:
>In AS7 there is no possibility for custom JNDI names of EJB beans and it's not planned for 7.1.
>Therefor the annotation #RemoteBindings and #LocalBindings are not available.
The recommended approach is to use the default bindings. However, custom JNDI names can also be defined via the #EJB annotation, as stated in this Oracle blog:
The developer can select an additional JNDI name that resolves to a particular client view of a session bean by using the #EJB annotation. Starting with Java EE 6, the #EJB name() attribute value can be prefixed with any one of the three portable Java EE namespaces : java:global, java:app, java:module. This has the effect of exporting the dependency into the selected scope.
I think what you are looking for is :
#Ejb(lookup="java:/global/somecustomPath")
As this will not affect where in JNDI the bean is bound but rather where to find it in JNDI.
If I'm right this is because JBOSS7 is a JEE6 application server and JEE6 introduced the concept of Portable Global JNDI names in JEE6.

Java Web Application deployment on JBoss 7.1

I intend to develop and deploy a simple web application using
EJB 3
JSP and servlet
JBoss 7
JPA
I have coded the application and created a standard ear with following structure
app.ear
|_ lib (with all required jars such as the commons logging)
|_ META-INF
|_ application.xml
|_ jboss-app.xml
|_ app_ejb.jar (contains a stateless EJB, an entity, persistence.xml etc...)
|_ app_web.war (jsps, servlet, web.xml etc..)
jboss-app.xml :- (library is the app name)
<!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
<jboss-app>
<loader-repository>library:app=ejb3</loader-repository>
</jboss-app>
application.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
<display-name>library</display-name>
<module>
<ejb>ejb_library.jar</ejb>
</module>
<module>
<web>
<web-uri>web_library.war</web-uri>
<context-root>web_library</context-root>
</web>
</module>
</application>
Now when I deploy this ear with the admin console of JBoss 7, the web module seems to have been deployed, even the pages are hit. However, the further part of the application where I try to inject the EJB in the servlet (as a instance varialbe using #EJB), fails.
There seems to be some problem in the way I am deploying the application.
I tried to find a tutorial where I could deploy the app in JBoss but with all that I am stuck till this.
Could anyone guide me with this? I am using JBoss for the first time and am not completely aware of JBoss specific configurations.
EJB that you are injecting, is it implementing an interface? and is that interface registered with the server? #Local or #Remote.
If not, then Try introducing a #Local interface and then your EJB implementation implementing that interface; and then, use that local interface to inject the EJB implementation.
Also, check the threads below;
JBoss 6: Injecting EJB into servlet
Inject an EJB into JAX-RS (RESTful service)
http://docs.jboss.org/ejb3/docs/tutorial/1.0.0/html/Injecting_EJB_in_Servlets.html
A silly thought, but can you re-arrange the modules declarations in application.xml; bring web modules first and ejb following it.
module -> web module
module -> ejb module
Moreover, this is also related to your situation:
http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ch01s04s02.html

JBoss 5 AS and EJB3 bean injection from servlets?

It was my understanding that JBossAS 5.x supported EJB3 bean injection in servlets with the #EJB3 annotation. I'm using the default configuration for JBossAS 5.0.1.GA and it's not working. I've added the mappedName argument to the #EJB annotation with the session beans JNDI name, and it just doesn't do anything. No apparent errors, the bean is just never injected.
The session beans are in the ejb-jar, the servlets in a war, everything is packaged in an ear. Manual JNDI lookups work just fine. Any ideas?
This may happen if your web.xml points to an older version of the spec. Ideally, it should be something like
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
This link may help a little too.
You should also check the jar file needed for EJB3 deployment in the classpath.JAr file is jboss-ejb3-ext-api.jar.

JMS Topic Creation in JBoss 5 AS

In Jboss 4, when I deployed an ear with an MDB for a topic that had not been specified in the deployment descriptors, the server would automatically create the topic (after posting a warning saying that topic didn't exist).
In Jboss 5, it doesn't seem to automatically create the topics anymore (errors out instead). Is there a configuration option somewhere that would allow automatic topic creation?
From the JBoss community forums -- This JIRA was added in 5AS.
Unfortunately it looks like there is no way to implement createDestination globally in the standardjboss.xml descriptor -- You have to add a custom jboss.xml descriptor to the ear deploying the mdb.
<jboss xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss_5_0.xsd" version="3.0">
<enterprise-beans>
<message-driven>
<ejb-name>MessageDriven</ejb-name>
<create-destination>true</create-destination>
</message-driven>
</enterprise-beans>
</jboss>