So playing around today I came across something I found strange and I was hoping someone
might be able to explain why the following behavior occurs.
In my example I have 4 classes..
//an ejb3 interface
| package test;
|
| import javax.ejb.Local;
|
| @Local
| interface Test
| {
| String test(TestUser testuser);
|
| }
|
//an ejb3 implementation class
| package test;
|
| import javax.ejb.Stateless;
| import org.jboss.annotation.ejb.LocalBinding;
| import org.jboss.annotation.ejb.Management;
| import org.jboss.annotation.ejb.Service;
|
| @Stateless(name = "Test")
| @LocalBinding(jndiBinding = "Test/local")
| public class TestImpl implements Test
| {
| public String test(TestUser testUser)
| {
|
| return testUser.sayHello();
| }
| }
|
//a simple pojo
| package test;
|
| import javax.naming.InitialContext;
|
| public class TestUser
| {
| public String test()
| {
| try
| {
| InitialContext context=new InitialContext();
| Test test=(Test)context.lookup("Test/local");
| return test.test(this);
| }
| catch(Exception e)
| {
| e.printStackTrace();
| }
| return null;
|
| }
|
| protected String sayHello()
| {
| return "Hello";
| }
| }
|
//and a simple servlet
| package servlet;
|
| import java.io.IOException;
| import javax.servlet.ServletException;
| import javax.servlet.http.HttpServlet;
| import javax.servlet.http.HttpServletRequest;
| import javax.servlet.http.HttpServletResponse;
| import test.TestUser;
|
| public class TestServlet extends HttpServlet
| {
|
| @Override
| protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
| {
| TestUser test=new TestUser();
| response.getWriter().write(test.test());
|
| }
|
| }
|
All classes except the servlet are in the same package.
My first deployment looks like this
|
|
| ${jboss.home}/server/myserver/deploy/
| test-core.jar
| test.Test
| test.TestUser
|
| ${jboss.home}/server/myserver/deploy/
| test-ejb.jar
| test.TestImpl
|
| ${jboss.home}/server/myserver/deploy/
| test.war
| WEB-INF/classes
| servlet.TestServlet
|
If i run this the deployment fails with this error
| java.lang.ClassNotFoundException: Unexpected error during load of: test.TestImpl,
msg=class test.TestImpl cannot access its superinterface test.Test
|
I thought this was strange because they are in the same package just different
archives...but then I thought ok maybe this isn't legal.
So then i took all those same components and deployed them in an ear...and everything
worked!
As one last test I removed the ejb3 annotations and just made the ejb classes pojos still
deployed serperately as described above (not in a .ear). Also instead of a jndi lookup in
the TestUser pojo I did a direct instantiation of the TestImpl class. They worked that way
as well.
So I guess I'm wondering why I can't do a direct deployment of ejb3 implementation
classes separately from their interfaces if the interfaces are package protected?
Thanks
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4042257#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...