为什么在JBOSS上部署.jar给我:java.lang.NoClassDefFoundError?

时间:2015-03-15 17:03:02

标签: java eclipse maven jboss ejb

我有两个maven项目:

1)名为 test 我有拖网接口

package interfaces.locals;
import javax.ejb.Local;
@Local
public interface IClientLocal {
void showClientName();
}

package interfaces.Remotes;
import javax.ejb.Remote;
@Remote
public interface IClientRemote {
void showClientName();
}

pom.xml看起来像:

<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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
    </dependency>
</dependencies>

2)名为 testImpl 我的实施类

pom.xml看起来像:

<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>testImpl</groupId>
<artifactId>testImpl</artifactId>
<version>0.0.1</version>
<dependencies>
    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.10</version>
    </dependency>
    <dependency>
        <groupId>test</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

Impl类看起来像:

package implimentations;
import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import interfaces.Remotes.IClientRemote;
import interfaces.locals.IClientLocal;
@Stateless
public class Client implements IClientLocal, IClientRemote {    
private final static Logger LOGGER=LoggerFactory.getLogger(Client.class);
public void showClientName() {
    LOGGER.info("The name of this client is ==> Alonso.");      
}

}

注意:当我在@Override方法上方添加anotation showClientName()时,它会给我一个错误:The method showClientName() of type Client must override a superclass method所以当我删除它时我会工作。

当我在Jboss服务器EAP 6上部署testImpl项目的jar时,它给了我这些错误:

`16:21:31,395 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class implimentations.Client in Module "deployment.testImpl-0.0.1.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link implimentations/Client (Module "deployment.testImpl-0.0.1.jar:main" from Service Module Loader)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:428) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.Module.loadModuleClass(Module.java:548) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:189) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_75]
at java.lang.Class.forName(Class.java:274) [rt.jar:1.7.0_75]
at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:85) [jboss-as-ee-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77) [jboss-as-ee-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_75]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]`
`Caused by: java.lang.NoClassDefFoundError: interfaces/locals/IClientLocal
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_75]
at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_75]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:345) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:423) [jboss-modules.jar:1.3.0.Final-redhat-2]`
`Caused by: java.lang.ClassNotFoundException: interfaces.locals.IClientLocal from [Module "deployment.testImpl-0.0.1.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
... 23 more`

1 个答案:

答案 0 :(得分:1)

在AS7或EAP6中,每个部署的JAR和WAR文件都被视为一个模块。在您的情况下,您有两个单独的部署test-0.0.1-SNAPSHOT.jartestImpl-0.0.1-SNAPSHOT.jar,您需要将依赖关系从testImpl-0.0.1-SNAPSHOT.jar添加到test-0.0.1-SNAPSHOT.jar

可以配置依赖关系,将条目添加到部署的MANIFEST.MF文件中。

例如:

Dependencies: deployment.test-0.0.1-SNAPSHOT

使用maven:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ejb-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <ejbVersion>3.1</ejbVersion>
        <archive>
            <manifestEntries>
                <Dependencies>deployment.test-0.0.1-SNAPSHOT</Dependencies>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

或者,您可以将所有jar文件部署在一个ear文件中以解决此问题。

查看更多: