Results 1 to 3 of 3
  1. #1
    Sara1991 is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Problem with running EJB project

    Hi
    I'm going to learn EJB but I really stuck at first step and I can't run even a simple project.
    I have these 3 simple files all in "bean" package:
    SayHello.java
    Java Code:
    package bean;
    
    import javax.ejb.EJB;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.naming.Context; 
    
    
    public class SayHello {
    	    	public  static void main(String[] args) {
    	    		InitialContext ic;
    				try {
    					ic = new InitialContext();
    	    		HelloUserBeanRemote user = (HelloUserBeanRemote) ic.lookup("foo");  
    	    		user.printName("blabla");
    				} catch (NamingException e) {
    					System.out.println("execption!");
    					// TODO Auto-generated catch block
    		//			e.printStackTrace();
    				}  
    	        }
    }
    HelloUserBeanRemote.java:
    Java Code:
    package bean;
    
    
    import javax.ejb.Remote;
    
    @Remote
    public interface HelloUserBeanRemote {
    	public void printName (String name);
    }
    HelloUserBean:
    Java Code:
    package bean;
    
    
    import javax.ejb.EJB;
    import javax.ejb.Stateless;
    
    @Stateless
    @EJB (name="foo", beanInterface=HelloUserBeanRemote.class)
    public class HelloUserBean implements HelloUserBeanRemote {
    
    		public void printName (String name){ 
    			System.out.println ("welcome" + name);
    	}
    
    }
    for more information I'm using EJB3 with glassfish3 and myeclipse10
    when I run this project:


    Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/api/naming/NamedNamingObjectProxy
    at java.lang.ClassLoader.findBootstrapClass(Native Method)
    at java.lang.ClassLoader.findBootstrapClass0(ClassLoa der.java:892)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 02)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 00)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at com.sun.hk2.component.LazyInhabitant.loadClass(Laz yInhabitant.java:124)
    at com.sun.hk2.component.LazyInhabitant.fetch(LazyInh abitant.java:111)
    at com.sun.hk2.component.EventPublishingInhabitant.ge t(EventPublishingInhabitant.java:135)
    at com.sun.hk2.component.AbstractInhabitantImpl.get(A bstractInhabitantImpl.java:78)
    at org.jvnet.hk2.component.Habitat$5.get(Habitat.java :703)
    at java.util.AbstractList$Itr.next(AbstractList.java: 345)
    at com.sun.enterprise.naming.impl.NamedNamingObjectMa nager.checkAndLoadProxies(NamedNamingObjectManager .java:73)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:462)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at bean.SayHello.main(SayHello.java:14)


    I've done a lot but I couldn't solve problem.
    someone mention to edit your classpath with this command:
    java -classpath $GLASSFISH_HOME/lib/gf-client.jar:~/Workspaces/MyEclipse\ 10/FirstEJB bean.SayHello
    but the result will be: Could not find the main class: bean.SayHello. Program will exit.
    also I try to add gf-cllient.jar to classpath using eclipse but it doesn't help at all

    really thankful for any help

  2. #2
    Sara1991 is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: Problem with running EJB project

    fortunately creating new workspace in home folder (last one was in root folder) solved the problem !

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,065
    Rep Power
    6

    Default Re: Problem with running EJB project

    Quote Originally Posted by Sara1991 View Post
    java -classpath $GLASSFISH_HOME/lib/gf-client.jar:~/Workspaces/MyEclipse\ 10/FirstEJB bean.SayHello
    but the result will be: Could not find the main class: bean.SayHello.
    I don't think that the second half of the classpath (after the colon) really was the correct path to your project output directory (where the packages with classes are), so that's why it didn't work. Java was basically telling you here "oi! I can't find the class anywhere on the classpath!"

    Rebuilding the workspace is not a solution, the only solution is one that came to be because you understood the problem. That way you can actually fix the problem in the future when you run into it again!

Similar Threads

  1. Replies: 21
    Last Post: 03-11-2012, 11:20 AM
  2. Replies: 7
    Last Post: 12-18-2011, 04:13 AM
  3. Replies: 2
    Last Post: 02-10-2011, 04:10 AM
  4. Replies: 26
    Last Post: 10-14-2010, 03:39 AM
  5. Replies: 0
    Last Post: 08-26-2009, 01:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •