简体   繁体   中英

Exception thrown EJB

I'm rather new to EJB.

I made this first one

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;

    }
}

But then when i make an other one:

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;

}

}

I get(glassfish server log):

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)

And now I'm like WHY ?? And how do I resolve this ?

I forgot to put @Remote on my interface classes. Just figured it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM