【问题标题】:Class not found in META-INF/lib after deployment on Glassfish although all jars are there在 Glassfish 上部署后,在 META-INF/lib 中找不到类,尽管所有 jar 都在那里
【发布时间】:2016-11-29 06:16:32
【问题描述】:

我面临以下问题:在将 eclipse ejb 项目部署到我的 glassfish 服务器时,我在服务器日志中为我的一个 bean 获得了“类 [...] 未找到”。因此,Eclipse 告诉我“部署失败”。

该错误的最终原因是我使用了来自第 3 方 jar (Apache Shiro) 的类。部署期间/之后,glassfish 无法找到使用的类。如果我跳过使用 Apache shiro 中的类的唯一一行代码,一切正常。

我使用 maven 进行依赖管理,并正确地将 maven 依赖添加到我的 Java 构建路径(因此在实现代码时我不会遇到任何错误)和我的 EJB 部署程序集。

maven 依赖项(所有需要的 jars)被正确打包在 META-INF/lib 下的我的 ejb-jar 文件中。 (1)通过 Eclipse 导出导出和检查 ejb-jar 文件,以及(2)通过分析 glassfish 服务器上的文件,对此进行了双重检查。所有 Apache shiro jar 都完全部署在 domain1/eclipseApps/My-App-root/META-INF/lib 下(我也尝试过 META-INF/classes,但错误相同)。

顺便说一句:当我在 domain1/lib 下添加 Apache shiro jar 时,一切正常。

因此,我认为我的类路径有问题,因此 glassfish 无法在 /META-INF/lib 下找到罐子。

我的 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>

我的 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>

我的 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>

我正在使用 Eclipse Mars.2 (4.5.2)、Glassfish 4.1、Java (JDK) 1.8.0_25

问题:为什么我的 glassfish 服务器无法为我的 ejb 项目找到部署到 META-INF/lib 的 jar,并且随后无法从Apache shiro 的 jar 文件?

【问题讨论】:

    标签: java glassfish ejb classpath


    【解决方案1】:

    如果需要,ejb 项目不能包含其他 jars 然后,您将需要一个包含您的 ejb 项目作为第三方库的 ear-project

    ear-项目 + ejb 项目 + apache-shiro

    【讨论】:

      猜你喜欢
      • 2011-01-31
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      相关资源
      最近更新 更多