2016-05-13 53 views
0

を解決するときに、私は次があります。java.lang.LinkageErrorの:ローダー制約違反:メソッド

1. EJBビジネス層に

package ejb.x.y; 

@Stateless 
public class FileFormatConvertor { 
    public byte[] fromExcelToCsv(Workbook workbook, Sheet sheet, String delimiter) throws Exception { 
     ... 
} 

2.豆をWeb層に

package web.x.y; 

@Named 
@SessionScoped 
public class FileUploadViewAction implements Serializable { 
    @EJB 
    private FileFormatConvertor fileFormatConvertor ; 
    // Other declarations 
    if (fileType == Type.EXCEL) { 
     bytesToUpload = fileFormatConvertor.fromExcelToCsv(workbook, sheet, delimiter); 
    } 
    // Rest of code 
} 

3. POMファイル

ear 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> 
    <parent> 
     <artifactId>xy-portal</artifactId> 
     <groupId>com.xy</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <groupId>com.xy</groupId> 
    <artifactId>ear-x-y</artifactId> 
    <version>${project.version}</version> 
    <packaging>ear</packaging> 
    <name>ear-x-y</name> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <build> 
     <finalName>ear-x-y</finalName> 
     <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> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-ear-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <version>6</version> 
        <defaultLibBundleDir>lib</defaultLibBundleDir> 
        <modules> 
         <webModule> 
          <groupId>com.xy</groupId> 
          <artifactId>web-x-y</artifactId> 
          <contextRoot>/xy</contextRoot> 
          <bundleFileName>xy-portal-web.war</bundleFileName> 
         </webModule> 
         <ejbModule> 
          <groupId>com.xy</groupId> 
          <artifactId>ejb-x-y</artifactId> 
          <bundleFileName>xy-portal-ejb.jar</bundleFileName> 
         </ejbModule> 
        </modules> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.jboss.as.plugins</groupId> 
       <artifactId>jboss-as-maven-plugin</artifactId> 
       <configuration> 
        <skip>false</skip> 
        <hostname>0.0.0.0</hostname> 
        <!--<hostname>xy</hostname>--> 
        <port>0000</port> 
        <filename>xy-portal-ear.ear</filename> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>com.xy</groupId> 
      <artifactId>xy-portal-ejb</artifactId> 
      <version>${project.version}</version> 
      <type>ejb</type> 
     </dependency> 
     <dependency> 
      <groupId>com.xy</groupId> 
      <artifactId>xy-portal-web</artifactId> 
      <version>${project.version}</version> 
      <type>war</type> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>resteasy-jaxb-provider</artifactId> 
      <version>2.3.1.GA</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>resteasy-jaxrs</artifactId> 
      <version>2.3.1.GA</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>xy-client</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>xy-datamodel</artifactId> 
      <version>${project.version}</version> 
     </dependency>  
    </dependencies>  
</project> 

のEJBの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> 
    <parent> 
     <artifactId>xy-portal</artifactId> 
     <groupId>com.xy</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <groupId>com.xy</groupId> 
    <artifactId>xy-portal-ejb</artifactId> 
    <version>${project.version}</version> 
    <packaging>ejb</packaging> 
    <name>xy-portal-ejb</name> 
    <properties> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencies>   
     <dependency> 
      <groupId>org.jboss.as</groupId> 
      <artifactId>jboss-as-ejb3</artifactId> 
      <version>7.1.2.Final</version> 
      <scope>provided</scope> 
      <exclusions> 
       <exclusion> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-validator</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency>  
     <dependency> 
      <groupId>org.jboss.spec</groupId> 
      <artifactId>jboss-javaee-6.0</artifactId> 
      <version>3.0.3.Final</version> 
      <type>pom</type> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.infinispan</groupId> 
      <artifactId>infinispan-core</artifactId> 
      <version>6.0.2.Final</version> 
     </dependency>   
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml-schemas</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>dom4j</groupId> 
      <artifactId>dom4j</artifactId> 
      <version>1.6.1</version> 
     </dependency>   
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId>       
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.arquillian.testng</groupId> 
      <artifactId>arquillian-testng-container</artifactId> 
      <scope>test</scope> 
     </dependency>  
     <dependency> 
      <groupId>org.jboss.shrinkwrap.resolver</groupId> 
      <artifactId>shrinkwrap-resolver-api</artifactId> 
      <scope>test</scope> 
     </dependency>  
     <dependency> 
      <groupId>org.jboss.shrinkwrap.resolver</groupId> 
      <artifactId>shrinkwrap-resolver-api-maven</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.shrinkwrap.resolver</groupId> 
      <artifactId>shrinkwrap-resolver-api-maven-archive</artifactId> 
      <scope>test</scope>   
     </dependency> 
     <dependency> 
      <groupId>org.jboss.shrinkwrap.resolver</groupId> 
      <artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId> 
      <scope>test</scope>   
     </dependency> 
     <dependency> 
      <groupId>org.eu.ingwar.tools</groupId> 
      <artifactId>arquillian-suite-extension</artifactId>   
      <scope>test</scope> 
     </dependency>  
     <dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>2.2</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.opencsv</groupId> 
      <artifactId>opencsv</artifactId> 
      <version>3.7</version> 
      <scope>test</scope> 
     </dependency>    
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-ejb-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <ejbVersion>3.1</ejbVersion> 
        <archive> 
         <manifestEntries> 
          <Dependencies>org.infinispan export</Dependencies> 
         </manifestEntries> 
        </archive> 
       </configuration> 
      </plugin>  
     </plugins> 
    </build> 
</project> 

ウェブの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> 
    <parent> 
     <artifactId>xy-portal</artifactId> 
     <groupId>com.xy</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>xy-portal-web</artifactId> 
    <version>${project.version}</version> 
    <packaging>war</packaging> 

    <name>xy-portal-web</name> 

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

    <dependencies> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml-schemas</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>dom4j</groupId> 
      <artifactId>dom4j</artifactId> 
      <version>1.6.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.primefaces.themes</groupId> 
      <artifactId>all-themes</artifactId> 
      <version>1.0.10</version> 
     </dependency> 

     <dependency> 
      <groupId>org.primefaces</groupId> 
      <artifactId>primefaces</artifactId> 
      <version>5.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.omnifaces</groupId> 
      <artifactId>omnifaces</artifactId> 
      <version>1.8.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.primefaces.extensions</groupId> 
      <artifactId>primefaces-extensions</artifactId> 
      <version>3.2.0</version> 
     </dependency> 

     <dependency> 
      <groupId>org.webjars</groupId> 
      <artifactId>font-awesome</artifactId> 
      <version>4.6.1</version> 
     </dependency>  

     <dependency> 
      <groupId>commons-fileupload</groupId> 
      <artifactId>commons-fileupload</artifactId> 
      <version>1.3</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>2.2</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>xy-client</artifactId> 
      <version>${project.version}</version> 
      <scope>provided</scope> 
      <exclusions>     
       <exclusion> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-validator</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>xy-portal-ejb</artifactId> 
      <version>${project.version}</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>xy-datamodel</artifactId> 
      <version>${project.version}</version> 
      <scope>provided</scope> 
      <exclusions> 
       <exclusion> 
        <groupId>javax.validation</groupId> 
        <artifactId>validation-api</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-validator</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-jpamodelgen</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>resteasy-jaxb-provider</artifactId> 
      <version>2.3.1.GA</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>resteasy-jaxrs</artifactId> 
      <version>2.3.1.GA</version> 
     </dependency> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>jaxrs-api</artifactId> 
      <version>3.0.8.Final</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-validator</artifactId> 
      <version>5.1.2.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.spec</groupId> 
      <artifactId>jboss-javaee-web-6.0</artifactId> 
      <version>3.0.3.Final</version> 
      <type>pom</type> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>jboss</groupId> 
      <artifactId>jbosssx</artifactId> 
      <version>3.2.3</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>jboss</groupId> 
      <artifactId>jboss-jaas</artifactId> 
      <version>3.2.3</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>net.glxn</groupId> 
      <artifactId>qrgen</artifactId> 
      <version>1.4</version> 
     </dependency> 
     <dependency> 
      <groupId>net.sf.barcode4j</groupId> 
      <artifactId>barcode4j-light</artifactId> 
      <version>2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>jexcelapi</groupId> 
      <artifactId>jxl</artifactId> 
      <version>2.6</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.7</source> 
        <target>1.7</target> 
       </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>   
     </plugins> 
    </build> 
</project> 

4.例外

Caused by: javax.faces.el.EvaluationException: java.lang.LinkageError: loader constraint violation: when resolving method "ejb.x.y.FileFormatConvertor.fromExcelToCsv(Lorg/apache/poi/ss/usermodel/Workbook;Lorg/apache/poi/ss/usermodel/Sheet;Ljava/lang/String;)[B" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, web.x.y.FileUploadViewAction, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for resolved class, ejb.x.y.FileFormatConvertor, have different Class objects for the type Lorg/apache/poi/ss/usermodel/Workbook;Lorg/apache/poi/ss/usermodel/Sheet;Ljava/lang/String;)[B used in the signature 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:] 
    ... 36 more 

私はこの例外を取得することが間違って何をしているのですか? これまで私は以下を行っています: 1.循環クラスパスの依存性を確認してください 2. ejbを管理対象BeanとしてWeb層に移動します(問題は解決しますが、Beanは他のクライアントによってアクセスされ、自然の家) 3.同様の問題/ソリューション・トレイルのためにこのサイトを検索けど...

が助けてください何も見つからなかった

答えて

0

あなたの戦争とejb.jarなどは、それぞれ独自のクラスローダを持っているので、各クラスローダは、独自のを持っていますpoiクラスの定義。

あなたはpoi jarとすべての一般的なjarをあなたのejb.jarに入れて、ear/libに戦争を起こさせてください。依存関係をejb.jarとwarのpom.xmlに "提供されている"とマークしてください。

このように、warとejb.jarの両方が、親クラスローダであるearクラスローダによって定義されたクラスを継承します。

クラスローダーで定義されたクラスを別のクラスローダーに渡すのではなく、共通のクラスローダーで定義されたクラスを使用してください。

+0

EARクラスローダーのようなものはありません。 EARファイルのlibディレクトリ内のすべてのjarファイルは、独自のモジュールにあるとみなされます。このモジュールは、EJB jarファイルやWARファイルなどのEARモジュールに表示されます。 EAR/libモジュールは効果的に独自のクラスローダーを取得しますが、確かに "親"ではありません。それ以外の場合は、あなたの答えはいいです。 –

+0

ありがとうmvera。それは魅力のように働いた –

0

私はこれを動作させました。私の答えは、ここでムンバイが言っていることを強調することです。 POMに

ここ
<dependencies> 
... 
    <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.14</version>   
    </dependency> 
... 
</dependencies> 

は私がやったことある...

  1. コピーし、この依存関係のエントリ(およびすべての共有の依存関係):戦争とEJBモジュールの両方のpom.xml内容は、次の依存関係を共有しましたあなたの耳のモジュールの.xml。

  2. マークのpom.xmlファイル内の結果の依存関係のエントリが今、あなたのプロジェクトを再ビルド

    <dependency> 
         <groupId>org.apache.poi</groupId> 
         <artifactId>poi</artifactId> 
         <version>3.14</version> 
         <scope>provided</scope> 
    </dependency> 
    
  3. 以下のようになりますようにEJBや戦争のモジュールのpom.xmlファイルで提供される共有の依存関係!

関連する問題