wood burning stoves 2.0*
The moose likes JBoss/WildFly and the fly likes JSPs don't see EJBs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JSPs don Watch "JSPs don New topic
Author

JSPs don't see EJBs

Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
Hi,

I have created some EJBs that are packaged in a jar, and jsp pages that are packaged in a war. If I deploy them the JBoss they work fine.

My problem comes when I try to package them both together in a ear file. JBoss seems like it is deploying both files from the ear, but none of my jsp pages can access the EJBs. I'm connecting through the local interface using:

Context ic = new InitialContext();
Object o = ic.lookup("UserManagerBean/local");

When I try this, I get this exception:

javax.naming.NameNotFoundException: local not bound

I've also found that if I copy the ear and jar file, everything works. So for whatever reason the jsp pages can't access the EJBs when they are packaged in the ear file.

Here is the structure of my ear file:

myApp.jar
myApp.war
meta-inf\application.xml

Here is application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">

<application>

<module>
<java>myApp.jar</java>
</module>

<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>myApp</context-root>
</web>
</module>
</application>

This is the first ear file I've tried to create, so I'm probably doing something wrong there. I've searched around and found lots of docs about the ear spec, but not many examples. Can anyone help? Thanks!

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Looks like you are using the wrong JNDI name to lookup. Follow the steps mentioned below, to figure out the JNDI name of your bean:

- Go to http://localhost:8080/jmx-console
- Search for service=JNDIView
- Click on that link
- On the page that comes up click on the Invoke button beside the list() method
- The page that comes up will show the contents of the JNDI tree. Search for your UserManagerBean there.

If you have a hard time understanding the output of the JNDI tree, just post the output here.


[My Blog] [JavaRanch Journal]
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
That was it!

When using jar/war, I could use beanName/local. In the ear format I had to use ejbAppName/beanName/local.

Thanks a lot for the help!

Mark
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
I'm stuck on this issue again. I did get this working on a JBoss server running on my PC, when I tried to deploy it to a production server I'm facing the same error again. But this time, nothing related to my app shows up in the Global JNDI Namespace. The JBoss version is the same, the only difference is that server is a 2 server cluster. Does that setup require different configuration of my app?

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Originally posted by Mark Sohm:
The JBoss version is the same, the only difference is that server is a 2 server cluster. Does that setup require different configuration of my app?



You mean you are running using the "all" server? Can you post the JBoss startup logs which can be found in server.log?
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
Sorry, I'm not sure what "all" server referrs to. If you let me know what to check I'll try and get the info. Here is the startup of my app from the server log files.

server1.log



server2.log



Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Originally posted by Mark Sohm:
Sorry, I'm not sure what "all" server referrs to. If you let me know what to check I'll try and get the info.


Your logs show that you are using the "all" server:

Originally posted by Mark Sohm:
2007-09-24 11:41:26,594 DEBUG [org.jboss.web.tomcat.tc5.TomcatDeployer] Initialized: {WebApplication: /C:/Jboss/server/all/tmp/deploy/tmp13740myApp.ear-contents/myApp-exp.war/, URL: file:/C:/Jboss/server/all/tmp/deploy/tmp13740myApp.ear-contents/myApp-exp.war/, classLoader: java.net.FactoryURLClassLoader@db1d6d:14359917} jboss.web:j2eeType=WebModule,name=//localhost/myApp,J2EEApplication=none,J2EEServer=none



These logs dont show much related to the JNDI bindings (logs like "Binding xxxx... to JNDI-name ...."). Also, does the JNDI view show anything related to your application?
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
There aren't any binding messages in the logs, nor does anything related to my app show up in the JNDI view (using the steps you posted earlier).

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Originally posted by Mark Sohm:
There aren't any binding messages in the logs, nor does anything related to my app show up in the JNDI view (using the steps you posted earlier).

Mark


Can you post the output of the following command:

- From the command prompt, go to C:/Jboss/server/all/farm/
- Run the following command:



From the logs that you posted, i am assuming that myApp.ear is the application that you are trying to deploy.
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
I don't have direct access to that directory, but here is the output from my local PC. Or if you think the output would be different on that server I can get someone to run that command there.



Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

I dont see why the application might not be getting deployed on the cluster server. The packaging looks fine to me. However the logs do not indicate that they picked up the myapp.jar. What does the contents of application.xml look like? Also, out of these 2 servers, which one is being picked up by the master server. And is there any other server in the cluster (network) which is started before these 2 servers and might be being picked up as the master?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

And by the way, in the JNDI tree view, do you see anything in the HA JDNI section (bottom of the page)? Check it on both the server's JNDI tree.
[ September 29, 2007: Message edited by: Jaikiran Pai ]
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
I'm back from vacation, so back to wrestling with this thing...

Neither server has anything listed in the HA-JNDI Namespace section.

I'll get the answers to your previous post.

Mark
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
Here is my application.xml file:



I confirmed that there are only 2 servers in this cluster, and that the log from server 1 (posted about) is the master.

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Originally posted by Mark Sohm:
Here is my application.xml file:





Isn't the myApp.jar the jar which contains the EJBs? If yes, then the application.xml should be:





Note, the line marked in bold. See if this change works. I am surprised that in a standalone (non-clustered) server, the EJB were deployed with this application.xml.
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
I made that change to the application.xml file but nothing changed. I see the same behaviour in the cluster server and nothing new shows up in the JNDI Namespace. Any other ideas?

Mark
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
I just found out that this is the first application deployed on this server that makes use of EJBs. Can anyone recommend any kind of official JBoss reference ear I could have them test to make sure the server is working?

Something simple that works in JBoss and involves JSPs talking to an EJB so we can verify that the server is working ok.

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Sorry about getting back late on this. I have been on vacation.

Originally posted by Mark Sohm:
Can anyone recommend any kind of official JBoss reference ear I could have them test to make sure the server is working?

Something simple that works in JBoss and involves JSPs talking to an EJB so we can verify that the server is working ok.



If you are using EJB3 and an appropriate version of JBoss (which supports EJB3), then you can try out the EJB3Trail/
[ October 20, 2007: Message edited by: Jaikiran Pai ]
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
No problem, I appreciate the help. I've been away myself as well.

I've made some progress in reproducing, the problem, although I'm still without a solution. The other server was running 4.0.5GA, where I had 4.0.4GA. I installed 4.0.5GA and now mirror the problem on my local PC.

Nothing about my app shows up in the java: Namespace or Global JNDI Namespace when deployed as an ear (same file deployed in both versions), but I do see it listed under Web Applications.

The output from JBoss after I deploy the app is below. Are there new deployment requirements for the later version of JBoss?

Mark

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

Mark,

Looking at this latest log that you posted, i believe that the server is not identifying the myApp.jar as a EJB module. For EJB2.x (in addition to an entry in application.xml) there should be an ejb-jar.xml file in the META-INF folder, for the jar to be identified as a EJB module. For EJB3, the jar should contain annotated classes for it to be identified as a EJB module. What version of EJB do you use? If it's EJB2.x, can you post the output of



Also, the logs in server.log file will provide some more information to what is happening. The console logs only show INFO level logs by default.
Mark Sohm
Greenhorn

Joined: Jul 11, 2007
Posts: 19
It's a EJB3 app. I'm not sure what annotated classes are. I created the app in JBoss Eclipse, so I assume it would have created what it needed.

Here is a link to the log file:

Log

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9958
    
163

The logs show that you are using JBoss-4.0.5GA, which does not have EJB3 support by default. You have to install jboss-EJB-3.0_RC9_Patch_1 (available here) for EJB3 support. I guess, that patch has a ant build file which needs to be run to place in the EJB3 deployers in the right place on the server. If you don't have a constraint on which version of JBoss you are going to use, then i would suggest you download the latest JBoss4.2.2 version which comes with EJB3 support by default.

The logs also show that while deploying myApp.jar:



2007-11-01 13:20:41,362 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment (init step) of package at: file:/C:/Program Files/jboss-4.0.5.GA/server/default/tmp/deploy/tmp64302myApp.ear-contents/myApp.jar
2007-11-01 13:20:41,362 DEBUG [org.jboss.deployment.JARDeployer] No xml files found
2007-11-01 13:20:41,362 DEBUG [org.jboss.deployment.MainDeployer] using deployer org.jboss.deployment.JARDeployer@19b04e2
2007-11-01 13:20:41,362 DEBUG [org.jboss.deployment.JARDeployer] looking for nested deployments in : file:/C:/Program Files/jboss-4.0.5.GA/server/default/tmp/deploy/tmp64302myApp.ear-contents/myApp.jar
2007-11-01 13:20:41,394 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] Added url: file:/C:/Program Files/jboss-4.0.5.GA/server/default/tmp/deploy/tmp64302myApp.ear-contents/myApp.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@5afcb1{ url=file:/C:/Program Files/jboss-4.0.5.GA/server/default/tmp/deploy/tmp64302myApp.ear ,addedOrder=41}
2007-11-01 13:20:41,394 DEBUG [org.jboss.deployment.MainDeployer] found 0 subpackages of file:/C:/Program Files/jboss-4.0.5.GA/server/default/tmp/deploy/tmp64302myApp.ear-contents/myApp.jar


The reason why the server is expecting the xml files (ejb-jar.xml) is because, its not able to identify it as a EJB3 module (in which case, no xml files are needed). So for you to get this working, you will have to either patch the current server with EJB3 support or install JBoss-4.2.2 (i recommend the latter).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSPs don't see EJBs
 
Similar Threads
ejb/war deployment
JBoss EAR structure
Jboss thrwos exception while startup:
Deploying EJB using MySql as a datasource
Deploying EJB using MySql as a datasource