ejb stateless example

Posted on 2017-01-29
Last Modified: 2017-03-20

I am working on below example

my code is
package com.example.ejbtest;
import javax.ejb.Stateless;

public class SLBean implements SLBeanRemote {

    public SLBean() {

    public String sayHello() {
        return "Hello World !!!";


Open in new window

package com.example.ejbtest;

import javax.ejb.Remote;

public interface SLBeanRemote {
    public String sayHello();

Open in new window

package com.example.ejbtest;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Test {

    public static void main(String[] args) {
        Context context;
        try {
            Properties properties = new Properties();
            properties.put("jboss.naming.client.ejb.context", true);
            context = new InitialContext(properties);

            String appName = "";
            String moduleName = "EJBTest";
            String distinctName = "";
            String beanName = SLBean.class.getSimpleName();
            String viewClassName = SLBeanRemote.class.getName();

            String ejbString = "ejb:" + appName + "/" + moduleName + "/"
                    + distinctName + "/" + beanName + "!" + viewClassName;


            SLBeanRemote remote = (SLBeanRemote) context.lookup(ejbString);

        } catch (NamingException e) {

Open in new window

jboss-ejb- properties

Open in new window

when i run
i am getting below error

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.example.ejbtest.Test.main(

i was not sure what are username and password i supposed to provide and where to double check..

i attached project structure.

please advise
Question by:gudii9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

gudii9 earned 0 total points
ID: 42056514

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question