为什么在 JBOSS 上部署 .jar 给我:java.lang.NoClassDefFoundError?
why the deployement of .jar on JBOSS gives me :java.lang.NoClassDefFoundError?
我有两个 Maven 项目:
1) named 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) named testImpl
我的实现在哪里 class:
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 class 看起来像:
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.");
}
}
注意:当我在 showClientName()
方法上方添加注解 @Override
时,它给出了错误: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.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`
在 AS7 或 EAP6 中,每个部署的 JAR 和 WAR 文件都被视为一个模块。在您的情况下,您有两个单独的部署 test-0.0.1-SNAPSHOT.jar
和 testImpl-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 文件中来解决此问题。
查看更多:
我有两个 Maven 项目:
1) named 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) named testImpl
我的实现在哪里 class:
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 class 看起来像:
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.");
}
}
注意:当我在 showClientName()
方法上方添加注解 @Override
时,它给出了错误: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.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`
在 AS7 或 EAP6 中,每个部署的 JAR 和 WAR 文件都被视为一个模块。在您的情况下,您有两个单独的部署 test-0.0.1-SNAPSHOT.jar
和 testImpl-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 文件中来解决此问题。
查看更多: