Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

NoClassDefFoundError when i look up EJB from tag handler class

Posted on 2006-04-14
20
Medium Priority
?
379 Views
Last Modified: 2010-04-01
   Tag handler class and jsp is deployed in one of the instance of jboss.using environment properties in the tag handler class i am trying to  look up EJB method(i.e in ear) deployed in another instances of jboss.  i got home interface at the next line i am getting this exception.its telling that not able to find that class .

i am doing remote look up from war to ear;

      java.lang.NoClassDefFoundError: db/DOCModel
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClass(ClassLoader.java:620)
      java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1629)
      org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:850)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1299)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
      java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      java.lang.Class.getDeclaredMethods0(Native Method)
      java.lang.Class.privateGetDeclaredMethods(Class.java:2365)
      


   
    public int doEndTag() throws javax.servlet.jsp.JspTagException
            {


            try  
                  {    

            
                        Hashtable contextProperty            = new java.util.Hashtable();
                        contextProperty.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                        contextProperty.put(Context.SECURITY_PRINCIPAL, "admin") ;
                        contextProperty.put(Context.SECURITY_CREDENTIALS, "welcome");
                        contextProperty.put(Context.PROVIDER_URL, "jnp://localhost:1099");


                        
                    
                        InitialContext            context          = new InitialContext(contextProperty);
                        DocumentSessionHome home         = (DocumentSessionHome)context.lookup("DocumentSessionBean");

                        System.out.println("home===="+home);*********************** home interface getting here

                        DocumentSession         remote            = (DocumentSession)home.create();
                        System.out.println("remote===="+remote); /////////////////  remote interface not printed

                        ArrayList mainList      = (ArrayList)remote.getDocumentIds();
                  }      
                  catch(java.io.IOException e)  
                  {          
                        throw new JspTagException("IO Error: " + e.getMessage());
                  }
                  catch(Exception e)  
                  {          
                        throw new JspTagException("Error: " + e.getMessage());
                  }
                        return EVAL_PAGE;  
                  
                  }
0
Comment
Question by:chaitu chaitu
  • 12
  • 3
  • 3
  • +1
20 Comments
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16453058
Tag handler class and jsp is deployed(in the form of war) in one of the instance of jboss.

from tag handler class i am trying to  look up EJB method(i.e in the form of ear) deployed in another instances of jboss.
DOCModel.class file is there in  ear but still it is throwing java.lang.NoClassDefFoundError.
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16456024
if you think all the JNDI names and other stuff are perfect just try

 
 
   InitialContext          context         = new InitialContext(contextProperty);
   Object ref = context.lookup("DocumentSessionBean");
   DocumentSessionHome home         = (DocumentSessionHome)PortableRemoteObject.narrow(ref,DocumentSessionHome.class");
    DocumentSession        remote          = (DocumentSession)home.create();

As such i don't think your JNDI name is correct just verify & continue.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16458897
now i am getting this exception

javax.servlet.jsp.JspTagException: Error: Receive timed out
      bus.Paging.doEndTag(Paging.java:94)
      org.apache.jsp.helloWorld_jsp._jspx_meth_mt_paging_0(org.apache.jsp.helloWorld_jsp:115)
      org.apache.jsp.helloWorld_jsp._jspService(org.apache.jsp.helloWorld_jsp:88)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16459042
put forward your helloworld.jsp there is some tag error in it.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459096
<%@ page import="java.util.*"  %>
<%@ taglib uri="mytags" prefix="mt" %>
<HTML>    <HEAD>        <TITLE>Hello World!</TITLE>
</HEAD>    <BODY BGCOLOR="#FFFFFF">
<HR>    

<mt:paging/>
<HR>  
</BODY>
</HTML>
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459207
sometimes its coming NoClassDefFoundError and sometimes  Receive timed out error
0
 
LVL 2

Expert Comment

by:borislavmarkov
ID: 16459223
Of course, you have to include your custom classes that EJB uses, they are serialized.

so make sure DOCModel is Serializable and include it your WAR where you invoked the EJB,
also change :
contextProperty.put(Context.PROVIDER_URL, "jnp://localhost:1099");
to be
contextProperty.put(Context.PROVIDER_URL, "localhost:1099");
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16459511
<%@ taglib uri="mytags" prefix="mt" %>

is that tag library named "mytags" is it there in WEB-INF folder direcly??.
Or is it there in some other folder inside WEB-INF???

and also check this link.

http://www.theserverside.com/discussions/thread.tss?thread_id=30166#147156
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459584
i dont understand one thing that i added Home interface and Remote interface classes  in the WAR;

do i addeed custom classes in WAR;those custom classes already there ear .
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459589
i already implemented simple example;it worked well now i am implementing remote look up;

problem lies in remote lookup onlyy
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459613
14:09:22,518 INFO  [STDOUT] home====DocumentSessionBeanHome
14:09:22,924 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: bus/DOCModel

          at java.lang.Class.getDeclaredMethods0(Native Method)
  at java.lang.Class.privateGetDeclaredMethods(Class.java:2365)
  at java.lang.Class.privateGetPublicMethods(Class.java:2488)
  at java.lang.Class.getMethods(Class.java:1406)
  at sun.misc.ProxyGenerator.generateClassFile(ProxyGenerator.java:409
  at sun.misc.ProxyGenerator.generateProxyClass(ProxyGenerator.java:30
  at java.lang.reflect.Proxy.getProxyClass(Proxy.java:484)
  at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:64
  at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:58
  at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.ja

  at org.jboss.system.JBossRMIClassLoader.loadProxyClass(JBossRMIClass
a:70)
  at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java

  at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputS
:238)
  at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:14
  at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:14
  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.ja

  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
  at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
  at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMP
xy.java:119)
  at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInte
va:227)
  at org.jboss.invocation.MarshallingInvokerInterceptor.invoke(Marshal
rInterceptor.java:37)
  at org.jboss.proxy.TransactionInterceptor.invoke(TransactionIntercep
6)
  at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.ja

  at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:1
  at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:86)
  at $Proxy50.create(Unknown Source)
  at bus.Paging.doEndTag(Paging.java:58)
  at org.apache.jsp.helloWorld_jsp._jspx_meth_mt_paging_0(org.apache.j
rld_jsp:91)
  at org.apache.jsp.helloWorld_jsp._jspService(org.apache.jsp.helloWor

  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWra
322)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.ja

  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorI
9)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodA
l.java:25)
  at java.lang.reflect.Method.invoke(Method.java:585)
  at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java

  at java.security.AccessController.doPrivileged(Native Method)
  at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
  at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.ja

  at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityU
61)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
nFilterChain.java:245)
  at org.apache.catalina.core.ApplicationFilterChain.access$000(Applic
rChain.java:50)
  at org.apache.catalina.core.ApplicationFilterChain$1.run(Application
n.java:156)
  at java.security.AccessController.doPrivileged(Native Method)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicat
hain.java:152)
  at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHead
ava:81)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorI
9)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodA
l.java:25)
  at java.lang.reflect.Method.invoke(Method.java:585)
  at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java

  at java.security.AccessController.doPrivileged(Native Method)
  at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
  at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.ja

  at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityU
17)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
nFilterChain.java:197)
  at org.apache.catalina.core.ApplicationFilterChain.access$000(Applic
rChain.java:50)
  at org.apache.catalina.core.ApplicationFilterChain$1.run(Application
n.java:156)
  at java.security.AccessController.doPrivileged(Native Method)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicat
hain.java:152)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrap
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459622
just tell me onething  if i want to acess one method in EJB deployed in another machine(in the form of ear;ejb's and custom classes are there),what classes do i add in my war.
0
 
LVL 1

Accepted Solution

by:
sriki77 earned 1200 total points
ID: 16459677
The NoClassDefFoundError occurs when the class is linked by the compiler and the class is absent during runtime. I mean, your EJB uses the DOCModel i guess, without which you couldn't haave compiled your EJB. During runtime its not finding the class.

Now, i accept that the classes are in the EAR, if the DOCModel class is part of a jar in the EAR, please put the jar in your WAR manifest - classpath. This is to say that my war uses the class files in the jar.

In the WAR Manifest.MF

Class-path: <jar containing DOCModel class>
or
Class-path: .

In the second case the classpath is set to the ear(. a dot) itself. This useful if your bus/DOCModel is directly in the EAR and not in any jar file.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459694
"I mean, your EJB uses the DOCModel i guess"
yes.

not only that class so many classes are there in ejb.jar;this jar is part of ear.that application is working fine.

"please put the jar in your WAR manifest - classpath"

how to put??first of all there no manifest file is there in war.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459703
THIS is MY PART OF build.xml file;how to create manifest file and add classpath into it..

<target name="build" description="Compile main source tree java files">  
<mkdir dir="${build.dir}"/>      
<javac destdir="${build.dir}" debug="on">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>  
</javac>  
</target>  
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${name}.war"    webxml="${web.dir}/WEB-INF/web.xml">    
<fileset dir="${web.dir}">            
<include name="**/*.*"/>        
</fileset>      
</war>    
<copy todir="${deploy.path}" preservelastmodified="true">  
<fileset dir=".">        
<include name="*.war"/>        
</fileset>      
</copy>
</target>
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16459718
once again i am explaining ..


war(in this taghandler class i am trying to look up ejb business method in ear deployed in node2 instance) deployed in jboss/node1 instance..

ear deployed in jboss/node2 instance..


in war i added only home and remote of DocumentSession class in WEB/classes .(do i need these classes in war);;anything else do i add in war.
0
 
LVL 2

Assisted Solution

by:borislavmarkov
borislavmarkov earned 800 total points
ID: 16459831
for normal lookup you need:

Home interfaces
Remote interfaces
Stubs and skeletons are loaded dynamically so you don't need them.
Anu custom classes that are passed as params to EJB or returned by the EJb are also NEEDED in WAR file.

Check if you didn't made any mess with classlaoders.
Put classes to be visible where your tag class is, same or parent classloader.
0
 
LVL 1

Expert Comment

by:sriki77
ID: 16459842
The manifest file is th MANIFEST.MF in the war file.

I understand you put the home and remote classes.
 But does it have DOCModel class there? Add it if its not there

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16467675
borislavmarkov ,sriki77

Once custom classes have added its starts working fine. only remote and home interfaces are enough to remote look up I THOUGHT custom classes will load dynamically(i added 5 custom class then its working fine.);

why do i need custom classes ?can't classloader load the classes dynamically?where the classloader reside??


0
 
LVL 2

Expert Comment

by:borislavmarkov
ID: 16467909
I think it can load them dynamically , you can use DynClassLoader but it is much more complex to switch this option.
Why do you need that. Anyway in your code you have to cast them to something usable.

If you want further info on dynamic classloading maybe you should write another question.

COPY FROM JBOSS DOC:

EJB DynClassLoader. The EJB DynClassLoader node is a subclass of URLClassLoader that is used to provide RMI dynamic class loading via the simple HTTP WebService. It specifies an emptyURL[] and delegates to the TCL as its parent class loader. If the WebService is configured to allowsystem level classes to be loaded, all classes in the UnifiedLoaderRepository3 as well asthe system classpath are available via HTTP
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This applies to Dell but may also apply to other manufacturers as well. We ran across a few machines that just dropped recently it trust relationship with the server. After doing the basic removing and joining the domain again, it changed to No logo…
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

577 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