抛出EJB的异常

时间:2013-10-21 13:27:40

标签: java netbeans glassfish ejb

我是EJB的新手。

我做了第一个

package Ejb01;

import java.util.Iterator;
import java.util.Vector;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;



@Singleton
@Startup
public class Ejb01 implements Ejb01Remote,Ejb01Local {

Vector geheugen;

@PostConstruct
void inhetbegin() {
    geheugen = new Vector();
    Contact c = new Contact();
    geheugen.add(c);
}

public void voegtoe(String number, String naam) {
    Contact c = new Contact(naam, number);
    geheugen.add(c);
}

@Override
public Vector geefGeheugen() {
    return geheugen;
}

@Override
public String giveName(String number) {
    String result = "NOT FOUND";
    for (Iterator it = geheugen.iterator(); it.hasNext();) {
        Contact i = (Contact) it.next();
        if(i.getNumber().equals(number))
        {
            result=i.getName();
        }
    }
       return result;

    }
}

但是当我再做一个时:

package Ejb02;

import Ejb01.Ejb01Local;
import Ejb01.Ejb01Remote;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


@Stateful
public class Ejb02 implements Ejb02Remote{

@Remove    
public void gedaan(){}
@EJB
private Ejb01Local boontje;


@Override
public String geefNaam() {
 String result="Not found.";

        //Context c= new InitialContext();
       // Ejb01Remote boontje=(Ejb01Remote)            
  c.lookup("java:global/EJBModule1/Ejb01!Ejb01.Ejb01Remote");
        result= boontje.giveName("0470/355.625");

    return result;

}

}

我得到(glassfish服务器日志):

ant -f /Users/eoghainverdonckt/Documents/netBeansProjects/EJB02 -DforceRedeploy=true -Ddirectory.deployment.supported=true -Dnb.wait.for.caches=true run
init:
EJBModule1.init:
EJBModule1.deps-jar:
EJBModule1.compile:
EJBModule1.library-inclusion-in-archive:
EJBModule1.dist:
deps-jar:
compile:
library-inclusion-in-archive:
dist-directory-deploy:
pre-run-deploy:
In-place deployment at /Users/eoghainverdonckt/Documents/netBeansProjects/EJB02/build/classes
Initializing...
deploy?DEFAULT=/Users/eoghainverdonckt/Documents/netBeansProjects/EJB02/build/classes&name=EJB02&libraries=/Users/eoghainverdonckt/Documents/netBeansProjects/EJBModule1/dist/EJBModule1.jar&force=true failed on GlassFish Server 3.1.2 
 Error occurred during deployment: Exception while deploying the app [EJB02] : Invalid ejb jar [EJB02]: it contains zero ejb. 
Note: 
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar. 
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.. Please see server.log for more details.
/Users/eoghainverdonckt/Documents/netBeansProjects/EJB02/nbproject/build-impl.xml:920: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 0 seconds)

现在我喜欢为什么?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我忘了把@Remote放在我的接口类上。  刚想通了。