我想在Jboss上部署多个grails应用程序。因为它们都使用相同的grails版本(2.1.1),我想从war文件中排除常见的jar并通过Jboss模块提供它们。对于初学者,我正在尝试使用一个应用程序,但无法使其正常工作。
我尝试了什么
defaultDependenciesProvided true
(inherits("global")
之前)Dependencies: commons.grails
添加到war 发生了什么
10:16:12,800 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "sofmk13-web-0.1.war"
10:16:23,095 WARN [org.jboss.modules] (MSC service thread 1-4) Failed to define class org.codehaus.groovy.grails.web.taglib.jsp.JspInvokeGrailsTagLibTag in Module "commons.grails:main" from local module loader @4ec57293 (roots: C:\development\tools\jboss-as-7.1.2.Final\modules,C:\development\repository\jboss): java.lang.LinkageError: Failed to link org/codehaus/groovy/grails/web/taglib/jsp/JspInvokeGrailsTagLibTag (Module "commons.grails:main" from local module loader @4ec57293 (roots: C:\development\tools\jboss-as-7.1.2.Final\modules,C:\development\repository\jboss))
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
at org.jboss.modules.Module.loadModuleClass(Module.java:527)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_17]
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) [rt.jar:1.7.0_17]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_17]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
at org.jboss.modules.Module.loadModuleClass(Module.java:527)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_17]
at java.lang.Class.forName(Class.java:266) [rt.jar:1.7.0_17]
at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54)
at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:81) [jboss-as-ee-7.1.2.Final.jar:7.1.2.Final]
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:116)
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_17]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_17]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_17]
Caused by: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/DynamicAttributes
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_17]
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) [rt.jar:1.7.0_17]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_17]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
... 31 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.tagext.DynamicAttributes from [Module "commons.grails:main" from local module loader @4ec57293 (roots: C:\development\tools\jboss-as-7.1.2.Final\modules,C:\development\repository\jboss)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 36 more
对于不同的类,有很多类似的警告。
有人能指出我接下来要尝试什么吗?我无法解读错误消息中究竟出错的地方。
谢谢!
答案 0 :(得分:2)
经过一些试验和错误后,我终于设法排除了一些罐子,并将它们作为模块提供。最难的部分是让所有jar依赖都正确。简要概述如下。我们首先介绍如何准备war存档以使用模块。然后我们描述了如何将模块添加到jboss。
在/ web-app / WEB-INF文件夹中创建 jboss-deployment-structure.xml 文件。这里我们指定应用程序使用哪些模块并设置适当的版本(使用slot参数)。请注意,这些模块提供了我们将在下一步中排除在战争之外的所有罐子。
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<dependencies>
<module name="commons.restGrailsJars" slot="2.1.1"/>
<module name="org.springframework" slot="3.1.2.RELEASE"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
添加代码以从war文件中排除共享jar。我们在 BuildConfig.groovy 中使用grails.war.resources配置选项。它允许我们在创建war之前进行一些额外的处理,因此我们可以从归档中删除共享jar(它们列在列表中)。在文件后附加以下行:
grails.war.resources = { resourceDir ->
File libDir = new File(resourceDir, 'WEB-INF/lib')
['aopalliance',
'asm',
'aspectjrt',
'aspectjweaver',
'cglib',
'commons-beanutils',
'commons-codec',
'commons-collections',
'commons-dbcp',
'commons-el',
'commons-fileupload',
'commons-io',
'oro',
'sitemesh',
'slf4j',
'spring-aop',
'spring-asm',
'spring-beans',
'spring-core',
'spring-expression',
'xpp3_min',
'h2',
'servlet-api']
.each { jarNameStart ->
libDir.eachFile { file ->
if (file.name.startsWith(jarNameStart)) {
file.delete()
println "deleted jar $file"
}
}
}
}
如果我们知道每个jar库需要哪些依赖项,那么添加模块非常容易。以下是为Spring版本3.2.3.RELEASE添加模块的示例。
将 module.xml 放在jar旁边。它看起来像这样:(注意更改的插槽值对应于发行版本和文件夹名称)
<module xmlns="urn:jboss:module:1.1" name="org.springframework" slot="3.2.3.RELEASE">
<resources>
<resource-root path="spring-asm-3.2.3.RELEASE.jar"/>
<resource-root path="spring-core-3.2.3.RELEASE.jar"/>
<resource-root path="spring-aop-3.2.3.RELEASE.jar"/>
<resource-root path="spring-beans-3.2.3.RELEASE.jar"/>
<resource-root path="spring-expression-3.2.3.RELEASE.jar"/>
</resources>
<dependencies>
<module name="aopalliance.aopalliance" export="true"/>
<module name="cglib.cglib" export="true"/>
<module name="org.aspectj.aspectjweaver" export="true"/>
<module name="org.apache.commons.logging" export="true"/>
<module name="org.apache.commons.pool" export="true"/>
<module name="javax.servlet.api"/>
<module name="javax.faces.api" slot="1.2" />
<module name="com.sun.jsf-impl" slot="1.2" />
<module name="org.jboss.vfs"/>
<module name="javax.persistence.api"/>
<module name="javax.xml.bind.api"/>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.annotation.api"/>
</dependencies>
</module>
如果缺少某些模块,则不会部署应用程序(或者它将会部署,但会发生奇怪的事情,例如电子邮件验证失败)。
您必须对要从war存档中排除的所有库执行类似操作。我设法排除了“准备WAR档案”部分(2。)中列出的所有罐子。
答案 1 :(得分:1)
您要包含的几个根资源已经是模块,因此您应该添加依赖项而不是包含JAR。你也应该避免添加jcl-over-slf4j-1.6.2.jar。已经提供了一个slf4j桥。
该错误似乎表明您需要依赖javax.servlet.jsp.api。
我没有详细介绍它,但我认为你的module.xml看起来应该更像以下。
<module xmlns="urn:jboss:module:1.1" name="commons.grails">
<resources>
<resource-root path="aopalliance-1.0.jar"/>
<resource-root path="asm-3.1.jar"/>
<resource-root path="aspectjrt-1.6.10.jar"/>
<resource-root path="aspectjweaver-1.6.10.jar"/>
<resource-root path="cglib-2.2.jar"/>
<resource-root path="commons-codec-1.5.jar"/>
<resource-root path="commons-dbcp-1.4.jar"/>
<resource-root path="commons-el-1.0.jar"/>
<resource-root path="commons-fileupload-1.2.2.jar"/>
<resource-root path="commons-validator-1.3.1.jar"/>
<resource-root path="concurrentlinkedhashmap-lru-1.2_jdk5.jar"/>
<resource-root path="ehcache-core-2.4.6.jar"/>
<resource-root path="grails-bootstrap-2.1.1.jar"/>
<resource-root path="grails-core-2.1.1.jar"/>
<resource-root path="grails-crud-2.1.1.jar"/>
<resource-root path="grails-datastore-core-1.1.0.RELEASE.jar"/>
<resource-root path="grails-datastore-gorm-1.1.0.RELEASE.jar"/>
<resource-root path="grails-datastore-simple-1.1.0.RELEASE.jar"/>
<resource-root path="grails-hibernate-2.1.1.jar"/>
<resource-root path="grails-logging-2.1.1.jar"/>
<resource-root path="grails-plugin-codecs-2.1.1.jar"/>
<resource-root path="grails-plugin-controllers-2.1.1.jar"/>
<resource-root path="grails-plugin-converters-2.1.1.jar"/>
<resource-root path="grails-plugin-datasource-2.1.1.jar"/>
<resource-root path="grails-plugin-domain-class-2.1.1.jar"/>
<resource-root path="grails-plugin-filters-2.1.1.jar"/>
<resource-root path="grails-plugin-gsp-2.1.1.jar"/>
<resource-root path="grails-plugin-i18n-2.1.1.jar"/>
<resource-root path="grails-plugin-log4j-2.1.1.jar"/>
<resource-root path="grails-plugin-mimetypes-2.1.1.jar"/>
<resource-root path="grails-plugin-scaffolding-2.1.1.jar"/>
<resource-root path="grails-plugin-services-2.1.1.jar"/>
<resource-root path="grails-plugin-servlets-2.1.1.jar"/>
<resource-root path="grails-plugin-url-mappings-2.1.1.jar"/>
<resource-root path="grails-plugin-validation-2.1.1.jar"/>
<resource-root path="grails-resources-2.1.1.jar"/>
<resource-root path="grails-spring-2.1.1.jar"/>
<resource-root path="grails-web-2.1.1.jar"/>
<resource-root path="groovy-all-1.8.8.jar"/>
<resource-root path="icu4j-51_1.jar"/>
<resource-root path="oro-2.0.8.jar"/>
<resource-root path="postgresql-9.2-1002.jdbc4.jar"/>
<resource-root path="sitemesh-2.4.jar"/>
<resource-root path="spring-aop-3.1.2.RELEASE.jar"/>
<resource-root path="spring-asm-3.1.2.RELEASE.jar"/>
<resource-root path="spring-aspects-3.1.2.RELEASE.jar"/>
<resource-root path="spring-beans-3.1.2.RELEASE.jar"/>
<resource-root path="spring-context-3.1.2.RELEASE.jar"/>
<resource-root path="spring-context-support-3.1.2.RELEASE.jar"/>
<resource-root path="spring-core-3.1.2.RELEASE.jar"/>
<resource-root path="spring-expression-3.1.2.RELEASE.jar"/>
<resource-root path="spring-jdbc-3.1.2.RELEASE.jar"/>
<resource-root path="spring-jms-3.1.2.RELEASE.jar"/>
<resource-root path="spring-orm-3.1.2.RELEASE.jar"/>
<resource-root path="spring-tx-3.1.2.RELEASE.jar"/>
<resource-root path="spring-web-3.1.2.RELEASE.jar"/>
<resource-root path="spring-webmvc-3.1.2.RELEASE.jar"/>
<resource-root path="xpp3_min-1.1.4c.jar"/>
</resources>
<dependencies>
<module name="javax.servlet.jsp.api" export="true"/>
<module name="javax.servlet.jstl.api" export="true"/>
<module name="com.h2database.h2"/>
<module name="org.apache.commons.beanutils"/>
<module name="org.apache.commons.collections"/>
<module name="org.apache.commons.lang"/>
<module name="org.apache.commons.io"/>
<module name="org.apache.commons.pool"/>
<module name="org.apache.log4j"/>
<module name="org.slf4j"/>
</dependencies>
</module>
我删除了一些不需要的依赖项,并在适当的时候添加了模块依赖项。