• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to deploy and run EJB 3? (Both Bean and client)

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I am trying to learn EJB 3 and I am struggeling with very first "Hello world" program.
I have many (dumb) doubts regarding EJB concept itself which I hope some of you might be able to clear.

I am tyring to run one simple EJB program but I guess I am missing something.

I have one @remote interface :




One bean class which implements this interface :


[color=darkblue][/color]

I have application.xml file which looks something like this :



I am using JBoss 5 server and eclipse galilelo IDE for this.
I used wizard to create project (project name is ConverterBean) and eclipse has created 5 kind of projects for me.

A) ConverterBean -->> this project contains application.xml
b) ConverterBeanClient -->>
c) ConverterBeanEJB -->> my remote interface and implementer class
d) ConverterBeanWeb -->>
e) ConverterBeanConnector -->>

Can anyone please tell me why all this projects are getting created???

After implementing interface, I have successfully deployed the bean. (I can see the message printed on console).

Now, I have created client in "ConverterBeanCLient" .
Its main class is as follows :



I have added "ConverterBeanEJB" as dependeny in this "ConverterBeanCLient" project.
Now when I try to run the client, I get following error :





I googled for above error, and I found out that somewhere I have to keep "jndi.properties" file. I do not know where to keep this file and what is the purpose of this file.
I looked into many tutorials and none of the tutorial has mentioned this file nor what is the purpose of this file.
Even JEE 5 tutorial from sun also does not mention this file.

Can anyone please tell me how to run client program?


I will upload my more dumb questions in next post
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I googled for above error, and I found out that somewhere I have to keep "jndi.properties" file. I do not know where to keep this file and what is the purpose of this file.


This properties file is used by JNDI to tell it where the server is located so that it can look up names. In this case, it will use the file to look find the server where the EJB is registered. The jndi.properties file needs to be in the classpath for your client, so put it into the base of your client's JAR file or into the base directory for the client's classes. The typical jndi.properties file for use with JBoss AS contains:



See if that gets you running. If not, I'll look over your code a little closer.
 
Chandrashekhar Kotekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Peter Johnson

Thanks for reply. I have solved the problem with the help of following tutorial.


http://javahowto.blogspot.com/2007/11/simple-ejb-3-on-jboss-application.html

The problem with other tutorials is that, some of the tutorials do not mention jndi.properties file and those who mention those files, they give information about particular app server like JBoss, Glass fish, etc.

Now I know what should be the content of jndi.properties file if we are going to use JBoss AS, but I dont know what should I write if we change the server.

Is there any book or tutorial which explains what should be the content of this file and what are other possible configurations in the file?
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

s there any book or tutorial which explains what should be the content of this file and what are other possible configurations in the file?


The contents are application server specific, so for every app server you will need to read its documentation to determine what the contents should be.
 
Chandrashekhar Kotekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Peter Johnson,

Thanks for reply.

I have one more question.

The contents are application server specific, so for every app server you will need to read its documentation to determine what the contents should be.



If contents jndi.properties file depends on specific server, then the application will become dependent on that particular server. Thus it cannot be deployed on other server without modifying code. Isnt it a disadvantage?

Also, I just wanted to confirm, the way we get the access to remote bean depends on particular server. Am I right?
For example,
In GlassFish server, we can just use @EJB annotation but in JBoss we have to do JNDI lookup with InitialContext object. Right?
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If contents jndi.properties file depends on specific server, then the application will become dependent on that particular server. Thus it cannot be deployed on other server without modifying code. Isnt it a disadvantage?


Not really. The config files are text file so easy to change, or at least that is how the thinking goes.

In GlassFish server, we can just use @EJB annotation but in JBoss we have to do JNDI lookup with InitialContext object. Right?


Depends on the version of JBoss AS. For 5.x you can use @EJB, for 4.x you need to do JNDI lookup.
 
Chandrashekhar Kotekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Peter,

Thank you very much for answering my stupid questions. Now I am comfortable with EJB and start working on my application.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chandra,

In response to your question:

I am using JBoss 5 server and eclipse galilelo IDE for this.
I used wizard to create project (project name is ConverterBean) and eclipse has created 5 kind of projects for me.

A) ConverterBean -->> this project contains application.xml
b) ConverterBeanClient -->>
c) ConverterBeanEJB -->> my remote interface and implementer class
d) ConverterBeanWeb -->>
e) ConverterBeanConnector -->>

Can anyone please tell me why all this projects are getting created???


this is the default behavior for Eclipse. "A" is the EAR for deployment, "B" I believe is a test client. "C" is the EJB implementation. "D" is the web portion for the project. "E" ... not sure, but not usually neeeded.

Typically, after you create your code and get it working with this layout, you would use a build script that would work out of one project and build the ear, war and jar's. After you get the hang of the build and putting all the right parts in the correct places, you would remove all the other projects and just work out of one. But since Eclipse does not generate any ant scripts for you (would be nice huh?) this layout gets deployed properly and is good for sepearation of logic, web and deployment.

HTH,

Peter
 
Chandrashekhar Kotekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Peter,

Thanks for answering my question.
Now I know why these many projects get created and what is the use of these projects. In fact, I am using those projects for my application and I am able to deploy one toy application on server.

 
Your buns are mine! But you can have this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic