在EAR

时间:2016-03-12 12:33:47

标签: maven java-ee ejb packaging ear

我目前正在开发一个依赖Java EE 7的原型.Maven用于依赖管理,插件maven-ear-plugin用于最终的EAR构建。然后将后者部署在wildfly 10.0应用程序服务器上。

项目结构如下(简化):

  • CONTROLER-API
  • CONTROLER-IMPL
  • 模型的API
  • 模型参数impl
  • system-parent(maven父包)
  • system-ear(生成耳朵)
  • 视图-web应用

EAR包含两个ejb3模块“controler-impl”和“model-impl”,以及Web应用程序“view-webapp”。相应地配置了maven-ear-plugin:

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-ear-plugin</artifactId>  
    <configuration>  
        <defaultLibBundleDir>lib</defaultLibBundleDir>  
        <generatedDescriptorLocation>META-INF</generatedDescriptorLocation>  
        <modules>  
            <ejbModule>  
                <groupId>com.domain.abc</groupId>  
                <artifactId>model-impl</artifactId>  
            </ejbModule>  
            <ejbModule>  
                <groupId>com.domain.abc</groupId>  
                <artifactId>controler-impl</artifactId>  
            </ejbModule>  
             <webModule>  
                <groupId>com.domain.abc</groupId>  
                <artifactId>view-webapp</artifactId>  
                <contextRoot>/myapp</contextRoot>  
            </webModule>  
        </modules>  
    </configuration>  
</plugin> 

到目前为止,一切都运行良好,原型已处于良好状态。

然而,我一直面临着一个问题,我无法应对:

在controler-impl中,我想使用reflection(org.reflections)来确定已经使用特定注释丰富的类。因此,我添加了相应的依赖项,jar的reflection-0.9.10.jar正确存储在EAR的lib文件夹中。

但是在运行时,我总是遇到一个ClassNotFoundException,告诉我ejb模块controler-impl中的类加载器无法在reflection-0.9.10.jar中找到类。为了进行调试,我浏览了类加载器层次结构并检查了哪些包和类可用。

我发现了三个类加载器:

  1. ModuleClassLoader(parent指2)
  2. AppClassLoader(parent指3)
  3. ExtClassLoader(parent为null)
  4. 他们都无法访问存放在中央EAR lib文件夹中的reflections-0.9.10.jar中的类。这很奇怪,因为我希望所有耳模块都可以访问这个密钥文件夹。

    当然,我在网上寻找现有的解决方案。例如,我发现以下文章更详细地解释了类加载器层次结构/分离。

    Packaging EJB 3 Applications - Developer.com

    根据本文中的表2,我假设我必须在ejb模块中添加清单文件。当然,我通过改变maven-ear-plugin的配置甚至将maven-ejb-plugin添加到模块来尝试这个。但我总是遇到错误“[...]中的类路径[...]没有指向类路径引用的有效jar”,并且仍然存在缺少对EAR lib文件夹的引用的基本问题(见下面的stacktrace)。

    我想我可能需要更好地配置maven-ear-plugin和/或maven-ejb-plugin(无论这意味着什么) - 有没有人知道如何做到这一点?还是我错过了重要的事情?

    非常感谢

    尼古拉斯

    由于评论中的要求而更新

    controler-impl的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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <groupId>com.domain.abc</groupId>
            <artifactId>prototype</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../system-parent/pom.xml</relativePath>
        </parent>
    
        <artifactId>controler-impl</artifactId>
        <packaging>jar</packaging>
        <name>Controler Implementation (EJB)</name>
    
        <dependencies>
            <!-- internal dependencies (provided by EAR) -->
            <!--  [...] -->
            <dependency>
                <groupId>com.domain.abc</groupId>
                <artifactId>controler-api</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.abc</groupId>
                <artifactId>model-api</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.abc</groupId>
                <artifactId>model-impl</artifactId>
                <type>ejb</type>
                <scope>provided</scope>
            </dependency>
    
            <!-- external dependencies (provided by EAR) -->
            <!--  [...] -->
            <dependency>
                <groupId>org.reflections</groupId>
                <artifactId>reflections</artifactId>
                <scope>provided</scope>
            </dependency>
    
        <build>
            <finalName>${project.artifactId}</finalName>
         </build>
    </project>
    

    EAR的application.xml(由maven-ear-plugin生成)

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC
        "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
        "http://java.sun.com/dtd/application_1_3.dtd">
    <application>
      <display-name>system-ear</display-name>
      <description>...</description>
      <module>
        <ejb>model-impl-1.0.0-SNAPSHOT.jar</ejb>
      </module>
      <module>
        <ejb>controler-impl-1.0.0-SNAPSHOT.jar</ejb>
      </module>
      <module>
        <web>
          <web-uri>view-webapp-1.0.0-SNAPSHOT.war</web-uri>
          <context-root>/myapp</context-root>
        </web>
      </module>
    </application>
    

    显示反射-0.9.10.jar无法访问的堆栈跟踪摘录

    09:48:27,222 ERROR [org.jboss.as.ejb3.invocation] (ServerService Thread Pool -- 67) WFLYEJB0034: EJB Invocation failed on component AccessControlManagerImpl for method public abstract org.apache.shiro.web.env.WebEnvironment com.domain.abc.controler.main.api.security.AccessControlManager.getPermssions(): javax.ejb.EJBException: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
        at org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation(ContainerManagedConcurrencyInterceptor.java:110)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:66)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
        at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)
        at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
        at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
        at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:195)
        at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:185)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
        at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)
        at com.domain.abc.controler.main.api.security.AccessControlManager$$$view4.getWebEnvironment(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:436)
        at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:127)
        at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
        at com.domain.abc.controler.main.impl.security.AccessControlManager$2108109816$Proxy$_$$_Weld$EnterpriseProxy$.getWebEnvironment(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
        at org.jboss.weld.proxies.AccessControlManager$2108109816$Proxy$_$$_WeldClientProxy.getWebEnvironment(Unknown Source)
        at com.domain.abc.view.frontend.webapp.security.CustomViewEnvLoaderListener.createEnvironment(CustomViewEnvLoaderListener.java:23)
        at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:133)
        at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
        at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
        at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:198)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        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)
        at org.jboss.threads.JBossThread.run(JBossThread.java:320)
    Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)
        at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
        at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:124)
        at org.jboss.as.ejb3.component.singleton.SingletonComponentInstanceAssociationInterceptor.processInvocation(SingletonComponentInstanceAssociationInterceptor.java:48)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
        ... 63 more
    Caused by: javax.ejb.EJBException: WFLYEJB0442: Unexpected Error
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:184)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:344)
        at org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:66)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
        at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
        ... 69 more
    Caused by: java.lang.NoClassDefFoundError: org/reflections/Configuration
        at com.domain.abc.controler.main.impl.security.AccessControlManagerImpl.postConstruct(AccessControlManagerImpl.java:71)
        at sun.reflect.GeneratedMethodAccessor313.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:114)
        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:103)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
        at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
        at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:100)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
        ... 85 more
    Caused by: java.lang.ClassNotFoundException: org.reflections.Configuration from [Module "deployment.prototype.ear.controler-impl-1.0.0-SNAPSHOT.jar:main" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
        ... 109 more
    

1 个答案:

答案 0 :(得分:0)

似乎提供的问题导致 controler-impl 模块的反射依赖关系。

具有所提供的依赖关系,即使它被提取并放入您的EAR / lib文件夹,您也无法将其绑定到JAR的类路径。

您需要从EAR pom.xml 文件中删除相关性,并从反射依赖项中删除提供的关键字< em> controler-impl 模块。

这样做,你需要Maven将依赖关系绑定到你的JAR的类路径,并通过传递性将它放在你的EAR / lib文件夹中。