1
votes

I'm facing the following problem: While deploying an eclipse ejb-project to my glassfish server, I'm getting a "Class [ ... ] not found" in my server's log for one of my beans. Therefore, Eclipse tells me that "deploy is failing".

The definitive cause for that error is that I'm using a class from a 3rd party jar (Apache Shiro). While/after the deployment, glassfish is not able to find the used class. If I skip the one and only line of code using the class from Apache shiro, everything works fine.

I use maven for dependency management and correctly added the maven dependencies to my Java build path (so I do not face any errors while implementing the code) and to my EJB deployment assembly.

The maven dependencies (all needed jars) are correctly packeted in my ejb-jar-file underneath META-INF/lib. This was double checked (1) by exporting and inspecting the ejb-jar-file by an Eclipse export and (2) by analysing the files on the glassfish server. All Apache shiro jars are fully deployed under domain1/eclipseApps/My-App-root/META-INF/lib (I also tried META-INF/classes with same error).

By the way: When I added the Apache shiro jars under domain1/lib, everything worked fine.

Thus, I assume that there is something wrong with my classpath so that glassfish is not able to find the jars under /META-INF/lib.

My pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>OrganizationAndSecurity</groupId>
  <artifactId>OrganizationAndSecurity</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>ejb</packaging>
  <name>Organization and security</name>
  <description>Provide facilities to manage organization units &amp; members, resources and permissions.</description>

  <build>
    <sourceDirectory>ejbModule</sourceDirectory>
    <resources>
      <resource>
        <directory>ejbModule</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-ejb-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <ejbVersion>3.2</ejbVersion>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-core</artifactId>
        <version>1.2.5</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-web</artifactId>
        <version>1.2.5</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
        <type>ejb</type>
    </dependency>
  </dependencies>
</project>

My ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd" version="3.2">
    <display-name>OrganizationAndSecurity</display-name>
</ejb-jar>

My glassfish-ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE    PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN" "http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd">
<glassfish-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>AuthenticatorMessageBean</ejb-name>
            <jndi-name>jms/queue/authenticationMessageQueue</jndi-name>
            <resource-ref>
                <res-ref-name>ConnectionFactory</res-ref-name>
                <jndi-name>authenticationMessageConnectionFactory</jndi-name>
            </resource-ref>
        </ejb>
    </enterprise-beans>
</glassfish-ejb-jar>

I am using Eclipse Mars.2 (4.5.2), Glassfish 4.1, Java (JDK) 1.8.0_25

Question: Why is my glassfish server not able to find the jars deployed to META-INF/lib for my ejb-project and, subsequently, isn't able to find the class used from an Apache shiro's jar file?

1

1 Answers

2
votes

A ejb-project cannot include additional jars, if you need Then, you will need a ear-project that includes both your ejb-project as third-party libraries

ear-project + ejb-project + apache-shiro