2015-06-23 4 views
1

У меня очень простой модуль ejb 3.0 с maven, у него есть только два сеансовых компонента один апатрид, а другой одноэлементный ... когда я пытаюсь развернуть проект на сервере Glassfish 3.0, я получил это исключение: произошлоGlassfish 3.0: Исключение при развертывании модуля ejb ... Недопустимый ejb j ar: он содержит нуль ejb

ошибки во время развертывания: исключение при развертывании приложения: Invalid EJB банки: она содержит ноль EJB. Примечание: 1. Действительный ejb jar требует, по крайней мере, одного сеанса, объекта (стиль 1.x/2.x) или управляемый сообщениями компонент. 2. EJB3 + entity beans (@Entity) - POJO и , пожалуйста, упакуйте их как библиотечную банку. 3. Если файл jar содержит действительные EJB, которые аннотируются с аннотациями уровня компонента EJB (@Stateless, @Stateful, @MessageDriven, @Singleton), пожалуйста, проверьте server.log, чтобы проверить, правильно ли обработаны аннотации. Дополнительную информацию см. На странице server.log.

Я проверяю проект с помощью средства проверки стекла, у меня есть это исключение, но я не знаю, что мне делать?

Verifier output unparsable 
Verifier output (C:\Users\Mariam.Moustafa\Documents\NetBeansProjects\web\EmployeesTimer\target\EmployeesTimer-1.0-SNAPSHOT.jar.xml) not found. 

Вот pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.unilever</groupId> 
    <artifactId>EmployeesTimer</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>ejb</packaging> 

    <name>EmployeesTimer</name> 

    <properties> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-bundle</artifactId> 
      <version>1.8</version> 
     </dependency> 

     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-api</artifactId> 
      <version>6.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.codehaus.jackson</groupId> 
      <artifactId>jackson-mapper-asl</artifactId> 
      <version>1.9.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.codehaus.jackson</groupId> 
      <artifactId>jackson-core-asl</artifactId> 
      <version>1.9.2</version> 
     </dependency> 

     <!-- slf4j Logger --> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.7</version> 
     </dependency>  

     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 

     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.7.7</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArguments> 
         <endorseddirs>${endorsed.dir}</endorseddirs> 
        </compilerArguments> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-ejb-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <ejbVersion>3.1</ejbVersion> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.1</version> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>copy</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${endorsed.dir}</outputDirectory> 
          <silent>true</silent> 
          <artifactItems> 
           <artifactItem> 
            <groupId>javax</groupId> 
            <artifactId>javaee-endorsed-api</artifactId> 
            <version>6.0</version> 
            <type>jar</type> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

    <repositories> 
     <repository> 
      <id>unknown-jars-temp-repo</id> 
      <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name> 
      <url>file:${project.basedir}/lib</url> 
     </repository> 
     <repository> 
      <id>m2.dev.java.net</id> 
      <url>http://download.java.net/maven/2</url> 
      <layout>default</layout> 
     </repository> 
     <repository> 
      <id>prime-repo</id> 
      <name>PrimeFaces Maven Repository</name> 
      <url>http://repository.primefaces.org</url> 
      <layout>default</layout> 
     </repository> 
    </repositories> 
</project> 

Я подтверждаю, что у меня есть 2 простой EJB

@Stateless public class EmployeesFacade {} 
@Singleton public class TimerService { 
@EJB EmployeesFacade emloyeesFacade; 
} 

Вот код:

Первый @singleton EJB боб

package com.employeestimer.services; 

import com.sun.jersey.api.client.Client; 
import com.sun.jersey.api.client.ClientResponse; 
import com.sun.jersey.api.client.WebResource; 
import com.unilever.employeestimer.enums.ConnectionEnum; 
import com.unilever.employeestimer.exceptions.BusinessException; 
import java.io.IOException; 
import javax.ejb.EJB; 
import javax.ejb.Schedule; 
import javax.ejb.Singleton; 
import javax.naming.NamingException; 
import javax.ws.rs.core.MediaType; 
import org.codehaus.jackson.JsonProcessingException; 
import org.slf4j.LoggerFactory; 


@Singleton 
public class TimerService { 
    static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(TimerService.class); 

    @EJB 
    EmployeesFacade emloyeesFacade; 

    private final static String U_ENGAGE_URL = "http://..../webresources/employees/update"; 

    @Schedule(second="*", minute="*/1",hour="*", persistent=false) 
    public void doWork() throws JsonProcessingException, IOException, NamingException{ 
     try{ 
      String input = emloyeesFacade.getUsersData(ConnectionEnum.USERNAME.getCode(), ConnectionEnum.PASSWORD.getCode()); 
      consumeRESTfulWebService(input);    
     }catch(BusinessException e){ 
      LOGGER.error("",e); 
     } 

    } 

    private void consumeRESTfulWebService(String input){    
     try { 
      LOGGER.debug("input = " + input); 
      Client client = Client.create(); 
      WebResource webResource = client.resource(U_ENGAGE_URL); 
      ClientResponse response = webResource.type(MediaType.TEXT_PLAIN).post(ClientResponse.class, input); 
      if (response.getStatus() != ClientResponse.Status.NO_CONTENT.getStatusCode()) { 
       throw new RuntimeException("Failed : HTTP error code : " 
        + response.getStatus()); 
      } 
      LOGGER.debug("Output from Server .... \n"); 
     } catch (Exception e) { 
      LOGGER.error("",e); 
    } 
    } 
} 

и вот Фасад боб:

package com.employeestimer.services; 

import com.employeestimer.beans.EmployeeData; 
import com.employeestimer.enums.ConfigurationsEnum; 
import com.employeestimer.enums.ConnectionEnum; 
import com.employeestimer.exceptions.BusinessException; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.Hashtable; 
import java.util.List; 
import javax.ejb.Stateless; 
import javax.naming.Context; 
import javax.naming.NamingEnumeration; 
import javax.naming.NamingException; 
import javax.naming.directory.Attribute; 
import javax.naming.directory.SearchControls; 
import javax.naming.directory.SearchResult; 
import javax.naming.ldap.Control; 
import javax.naming.ldap.InitialLdapContext; 
import javax.naming.ldap.LdapContext; 
import javax.naming.ldap.PagedResultsControl; 
import javax.naming.ldap.PagedResultsResponseControl; 
import org.codehaus.jackson.JsonProcessingException; 
import org.codehaus.jackson.map.ObjectMapper; 
import org.codehaus.jackson.map.ObjectWriter; 
import org.slf4j.LoggerFactory; 


@Stateless 
public class EmployeesFacade { 

    static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(EmployeesFacade.class); 

    public String getLDAPConnectionType() { 
     return ConfigurationsEnum.LDAP_Connection_Type.getCode(); 
    } 

    public String getDomain() { 
     return ConfigurationsEnum.DOMAIN.getCode(); 
    } 

    public String getLDAPIP() { 
     return ConfigurationsEnum.LDAP_IP.getCode(); 
    } 

    public String getLDAPPort() { 
     return ConfigurationsEnum.LDAP_PORT.getCode(); 
    } 

    public String getLDAPBase() { 
     return ConfigurationsEnum.LDAP_BASE.getCode(); 
    } 

    private LdapContext getContext(String username, String password) throws BusinessException, NamingException { 
     Hashtable env = new Hashtable(); 
     if (getDomain() == null || getLDAPConnectionType() == null 
       || getLDAPIP() == null || getLDAPPort() == null) { 
      throw new BusinessException("error_general"); 
     } 
     String domain = getDomain(); 
     String url = getLDAPConnectionType() + "://" + getLDAPIP() + ":" + getLDAPPort(); 
     env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
     env.put(Context.PROVIDER_URL, url); 
     env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
     env.put(Context.REFERRAL, "follow"); 
     if (!username.contains("@")) { 
      username = username + "@" + domain; 
     } 
     env.put(Context.SECURITY_PRINCIPAL, username); 
     env.put(Context.SECURITY_CREDENTIALS, password); 
     return new InitialLdapContext(env, null); 
    } 

    public String getUsersData(String username, String password) throws BusinessException, JsonProcessingException, IOException, NamingException { 
     List<EmployeeData> employeelist = new ArrayList<EmployeeData>(); 
     EmployeeData employee; 
     String json = ""; 
     try { 
      LdapContext context = getContext(username, password); 
      SearchControls constraints = new SearchControls(); 
      constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); 
      String[] attrIDs = {"mail"}; //, "sn", "cn", "c", "l"}; 
      constraints.setReturningAttributes(attrIDs); 
      // Activate paged results 
      int pageSize = Integer.parseInt(ConnectionEnum.PAGESIZE.getCode()); 
      byte[] cookie = null; 
      context.setRequestControls(new Control[]{new PagedResultsControl(pageSize, 
       Control.NONCRITICAL)}); 
      int total; 
      NamingEnumeration<SearchResult> result = null; 
      do { 
       /* perform the search */ 
       result = context.search(getLDAPBase(), "(&(objectClass=User)(c=EG))", constraints); 
       /* for each entry print out name + all attrs and values */ 
       while (result != null && result.hasMore()) { 
        SearchResult entry = (SearchResult) result.next(); 
        employee = new EmployeeData(); 
        Attribute attribute; 

        if (entry.getAttributes() != null) { 
         if (entry.getAttributes().get("mail") != null) { 
          attribute = entry.getAttributes().get("mail"); 
          employee.setEmail(attribute != null ? attribute.toString().replace("mail: ", "") : ""); 
          employeelist.add(employee); 
         } 
        } 
      } 
       // Examine the paged results control response 
       Control[] controls = context.getResponseControls(); 
       if (controls != null) { 
        for (int i = 0; i < controls.length; i++) { 
         if (controls[i] instanceof PagedResultsResponseControl) { 
          PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; 
          total = prrc.getResultSize(); 
          if (total != 0) { 
           LOGGER.debug("***************** END-OF-PAGE " + "(total : " + total + ") *****************\n"); 
          } else { 
           LOGGER.debug("***************** END-OF-PAGE " + "(Page no. " + i + ") ***************\n"); 
          } 
          cookie = prrc.getCookie(); 
         } 
        } 
       } else { 
        LOGGER.debug("No controls were sent from the server"); 
       } 
       // Re-activate paged results 
       context.setRequestControls(new Control[]{new PagedResultsControl(
        pageSize, cookie, Control.CRITICAL)}); 
      } while (cookie != null); 
      //result.close(); 
      context.close(); 
      ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); 
      json = ow.writeValueAsString(employeelist); 
      LOGGER.debug("\n \n \n ************* \n ************* \n ************* \n \n THE SIZE = " + employeelist.size() + "\n \n ************* \n ************* \n ************* \n \n \n"); 
     } catch (NamingException ex) { 
      String detailmessage = ex.getExplanation(); 
      if (detailmessage.contains(" 32 ")) { 
       // User not Found 
       throw new BusinessException("error_invalidUser"); 
      } else if (detailmessage.contains(" 49 ")) { 
       if (detailmessage.contains(" 775 ") || detailmessage.contains(" 701 ") || detailmessage.contains(" 533 ")) { 
        //Invalid Account 
        throw new BusinessException("error_invalidAccount"); 
       } else { 
        //Invalid Username or password 
        throw new BusinessException("error_invalidUsernamePassword"); 
       } 
      } else { 
       LOGGER.error("error_general", ex); 
       throw new BusinessException("error_general"); 
      } 
     } 
     return json; 
    } 
} 
+1

Пожалуйста, добавьте 'pom.xml' на вопрос ... – unwichtich

+0

@unwichtich pom.xml добавлен –

ответ

2

Я не вижу проблемы с установкой. Если у вас действительно есть какой-то класс, аннотированный с @Singleton или @Stateless внутри этого проекта, это должно сработать.

Но одним из важных моментов является то, что если у вас есть какие-либо зависимости, которые недоступны в библиотеках Glassfish, вам необходимо упаковать их с помощью приложения, что невозможно при упаковке EJB/JAR. Вы должны упаковать его как WAR или EAR-файл.

Для быстрого запуска, попробуйте следующее:

Изменение

<packaging>ejb</packaging> 

к

<packaging>war</packaging> 

и изменить

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ejb-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
       <ejbVersion>3.1</ejbVersion> 
      </configuration> 
     </plugin> 

в

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 

Если вы хотите упаковать его в качестве EAR, вы можете использовать maven-ear-plugin.

Смотрите также:

+0

дорогой неочтич, когда я попробую ваше предложение, он отлично работает, и Glassfish успешно разворачивает военный файл! Но как насчет модуля EJB? как я могу развернуть в GlassFish? в чем причина этой проблемы? !!! Я подтверждаю, что у меня есть 2 простой EJB @ Stateless общественного класса EmployeesFacade {} @ Singleton класс TimerService общественности { @ EJB EmployeesFacade emloyeesFacade; } –

+1

См. Третий пункт в сообщении об ошибке. Внутри 'server.log' может появиться другое сообщение об ошибке. – unwichtich

+0

server.log не имеет никаких исключений! также, когда я запускаю инструмент верификации для WAR, я получил тот же результат ... Результат проверки несовместим Выход верификатора (C: \ Users \ Mariam.Moustafa \ Documents \ NetBeansProjects \ web \ EmployeesTimer \ target \ EmployeesTimer-1.0-SNAPSHOT .war.xml) не найден. –

Смежные вопросы