代码之家  ›  专栏  ›  技术社区  ›  Suresh Atta

原因:java.lang.Linkage错误:链接失败com/---[重复]

  •  1
  • Suresh Atta  · 技术社区  · 8 年前

    下面是我的maven配置

    <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.trbrew.commerce.brewtique</groupId>
        <artifactId>BrewtiqueProject</artifactId>
        <packaging>pom</packaging>
        <version>1.0</version>
        <modules>
            <module>ejb</module>
            <module>ear</module>
            <module>web</module>
        </modules>
    
        <repositories>
            <repository>
                <id>maven2-repository.dev.java.net</id>
                <name>Java.net Repository for Maven</name>
                <url>http://download.java.net/maven/2/</url>
                <layout>default</layout>
            </repository>
        </repositories>
    
        <dependencies>
        </dependencies>
    

    还有儿童彩球

    <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.trbrew.commerce</groupId>
        <artifactId>TrBrewCommerce</artifactId>
        <packaging>jar</packaging>
        <version>1.0</version>
        <name>TrBrewCommerce</name>
        <url>http://maven.apache.org</url>
    
        <dependencies>
    
    
        <dependency>
          <groupId>com.koinplus</groupId>  
           <artifactId>KoinPlusCommons</artifactId>  
           <version>1.0</version> 
           <scope>system</scope>
           <systemPath>C://Users/trbrewjars/KoinPlusCommons-1.0.jar</systemPath>
         </dependency>
    
        <dependency>
          <groupId>com.trbrew.common</groupId>  
           <artifactId>TrBrewCommons</artifactId>  
           <version>1.0</version> 
           <scope>system</scope>
           <systemPath>C://Users/trbrewjars/TrendBrewCommons-1.0.jar</systemPath>
         </dependency>
    
    
    
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>7.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-collections4</artifactId>
                <version>4.1</version>
            </dependency>
             <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.20</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>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    耳塞模块Pom

    <?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">
        <parent>
            <artifactId>BrewtiqueProject</artifactId>
            <groupId>com.tbrew.commerce.brewtique</groupId>
            <version>1.0</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <artifactId>Brewtique</artifactId>
        <packaging>ear</packaging>
        <dependencies>
            <dependency>
                <groupId>com.trbrew.commerce.brewtique</groupId>
                <artifactId>ejb</artifactId>
                <version>1.0</version>
                <type>ejb</type>
            </dependency>
            <dependency>
                <groupId>com.trbrew.commerce.brewtique</groupId>
                <artifactId>web</artifactId>
                <version>1.0</version>
                <type>war</type>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.10.1</version>
                    <configuration>
                        <!--<defaultLibBundleDir>lib</defaultLibBundleDir>-->
                        <modules>
                            <webModule>
                                <groupId>com.trbrew.commerce.brewtique</groupId>
                                <artifactId>web</artifactId>
                            </webModule>
                            <ejbModule>
                                <groupId>com.trbrew.commerce.brewtique</groupId>
                                <artifactId>ejb</artifactId>
                            </ejbModule>
                        </modules>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    
    </project>
    

    ejb模块的Pom

    <?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">
        <parent>
            <artifactId>BrewtiqueProject</artifactId>
            <groupId>com.trbrew.commerce.brewtique</groupId>
            <version>1.0</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>ejb</artifactId>
        <packaging>ejb</packaging>
    
        <dependencies>
            <dependency>
                <groupId>com.trbrew.commerce</groupId>
                <artifactId>TrBrewCommerce</artifactId>
                <version>1.0</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ejb-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <ejbVersion>3.0</ejbVersion>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project> 
    

    运行生成的ear文件时遇到的错误是

    17:31:09,694 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.subunit."Brewtique-1.0.ear"."ejb-1.0.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."Brewtique-1.0.ear"."ejb-1.0.jar".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of subdeployment "ejb-1.0.jar" of deployment "Brewtique-1.0.ear"
            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.LinkageError: Failed to link com/trendbrew/commerce/brewtique/catalog/CatalogManagementService (Module "deployment.Brewtique-1.0.ear.ejb-1.0.jar:main" from Service Module Loader)
            at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:437)
            at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
            at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
            at org.jboss.modules.Module.loadModuleClass(Module.java:560)
            at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
            at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
            at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
            at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
            at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:348)
            at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54)
            at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:85)
            at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
            ... 5 more
    Caused by: java.lang.NoClassDefFoundError: com/koinplus/common/GenericKoinPlusService
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
            at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
            at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
            ... 19 more
    Caused by: java.lang.ClassNotFoundException: com.koinplus.common.GenericKoinPlusService from [Module "deployment.Brewtique-1.0.ear.ejb-1.0.jar:main" from Service Module Loader]
            at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
            at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
            at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
            at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
            at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
            ... 23 more
    
    17:31:09,725 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0003: Processing weld deployment web-1.0.war
    17:31:09,804 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "Brewtique-1.0.ear")]) - failure description: {
        "WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"Brewtique-1.0.ear\".\"ejb-1.0.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"Brewtique-1.0.ear\".\"ejb-1.0.jar\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of subdeployment \"ejb-1.0.jar\" of deployment \"Brewtique-1.0.ear\"
        Caused by: java.lang.LinkageError: Failed to link com/trendbrew/commerce/brewtique/catalog/CatalogManagementService (Module \"deployment.Brewtique-1.0.ear.ejb-1.0.jar:main\" from Service Module Loader)
        Caused by: java.lang.NoClassDefFoundError: com/koinplus/common/GenericKoinPlusService
        Caused by: java.lang.ClassNotFoundException: com.koinplus.common.GenericKoinPlusService from [Module \"deployment.Brewtique-1.0.ear.ejb-1.0.jar:main\" from Service Module Loader]"},
        "WFLYCTL0180: Services with missing/unavailable dependencies" => [
            "jboss.deployment.unit.\"Brewtique-1.0.ear\".batch.environment is missing [jboss.deployment.unit.\"Brewtique-1.0.ear\".beanmanager]",
            "jboss.deployment.unit.\"Brewtique-1.0.ear\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"Brewtique-1.0.ear\".beanmanager]",
            "jboss.deployment.subunit.\"Brewtique-1.0.ear\".\"web-1.0.war\".batch.environment is missing [jboss.deployment.subunit.\"Brewtique-1.0.ear\".\"web-1.0.war\".beanmanager]",
            "jboss.persistenceunit.\"Brewtique-1.0.ear/ejb-1.0.jar#tbCommPersistence\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasource.wishinity]",
    

    耳朵文件部署在Wildfly上,无法破解原因。有线索吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   davidxxx    8 年前

    在这里:

    <dependency>
      <groupId>com.koinplus</groupId>  
       <artifactId>KoinPlusCommons</artifactId>  
       <version>1.0</version> 
       <scope>system</scope>
       <systemPath>C://Users/trbrewjars/KoinPlusCommons-1.0.jar</systemPath>
     </dependency>
    
    <dependency>
      <groupId>com.trbrew.common</groupId>  
       <artifactId>TrBrewCommons</artifactId>  
       <version>1.0</version> 
       <scope>system</scope>
       <systemPath>C://Users/trbrewjars/TrendBrewCommons-1.0.jar</systemPath>
     </dependency>
    

    使用 system 范围
    它阻止您在TrBrewCommerce工件的解析中以及在最终的EAR工件中拥有这些依赖项。
    如果您希望这些jar包含在您的EAR中,请使用技巧保持 系统
    一种更干净的方法是在maven存储库中安装这两个jar。 之后,您可以删除作用域 系统 (在这种情况下,范围 runtime 默认情况下将使用)和依赖项声明中的系统路径,例如:

    <dependency>
      <groupId>com.koinplus</groupId>  
       <artifactId>KoinPlusCommons</artifactId>  
       <version>1.0</version> 
     </dependency>
    
    <dependency>
      <groupId>com.trbrew.common</groupId>  
       <artifactId>TrBrewCommons</artifactId>  
       <version>1.0</version> 
     </dependency>
    

    要安装Maven工件,您需要 install-file 目标:

    https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html