簡體   English   中英

java.lang.LinkageError:違反加載程序約束:解析方法時

[英]java.lang.LinkageError: loader constraint violation: when resolving method

我有以下內容:

1.業務層的EJB

package ejb.x.y;

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

2. web層中的bean

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文件

耳朵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. 在此站點上搜索類似的問題/解決方案,但一無所獲

請幫忙...

我得到這個工作。 我的回答只是為了強調 mvera 在這里所說的內容。例如,war 和 ejb 模塊的 pom.xml 內容共享以下依賴項:

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

這就是我所做的......

  1. 將此依賴項(以及所有共享依賴項)復制到 ear 模塊中的 pom.xml。

  2. 將共享依賴項標記為在 ejb 和 war 模塊的 pom.xml 文件中提供,這樣 pom.xml 文件中的結果依賴項現在看起來類似於以下內容

    <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> <scope>provided</scope> </dependency>
  3. 重建你的項目!

war 和 ejb.jar 都有自己的類加載器,因此每個類加載器都有自己的 poi 類定義。

您應該嘗試將 poi jar 和所有常見的 jar 放入您的 ejb.jar 並在 ear/lib 中進行戰爭。 在 ejb.jar 和 war 的 pom.xml 中將依賴項標記為“已提供”。

這樣,war 和 ejb.jar 都將繼承由它們的父類加載器 ear 類加載器定義的類。

您永遠不應該嘗試將類加載器中定義的類傳遞給另一個類加載器,而是使用公共類加載器中定義的類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM