EJB Standalone Client JBoss AS7.1.1

Creating a standalone EJB-client application works like the following.

If you use maven, just include the following dependency:

<dependency>
  <groupId>org.jboss.as</groupId>
  <artifactId>jboss-as-ejb-client-bom</artifactId>
  <type>pom</type>
  <version>7.1.1.Final</version>
</dependency>

Then you need a file jboss-ejb-client.properties in your classpath. Here an example:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=true
remote.connection.default.host=localhost
remote.connection.default.port=4447
remote.connection.default.username=username
remote.connection.default.password=password

If you haven’t changed default configuration the username+passwort are added with the add-user script in the bin-folder of your jboss.

In your code you just do the following:

Hashtable<String, String> jndi = new Hashtable<String, String>();
jndi.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");		
Context context = new InitialContext(jndi);

String viewClassName = MyInterface.class.getName();
String ejbPath = "ejb:" + appName + "/" + moduleName + "/"
 + distinctName + "/" + beanName + "!" + viewClassName;

MyInterface c = context.lookup(ejbPath);

For further information how to create the ejb-path just have a look at https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

In short:

  • appName: name of your ear file without ending
  • moduleName: name of your ejb file without ending
  • distinctName: optional name you can set – haven’t used this yet..
  • beanName: the simplename of your bean class
  • viewClassName: the full quallified name of your remote interface

e.g. ejb:/test/test-ejb-1.0.0/TestBean!full.qual.MyInterface

 

Leave a Comment