JBOSS EAP 6 系列六 公共模块的jar配置到jboss的modules详细配置

朱雀 2020-12-04 18:01 1061阅读 0赞

1:原则上除了自己写的代码之外,公共的jar不应该都在打包的时候打包到ear里面,这样的话包太大,也不符合的分层的逻辑,在jboss容器内部,每个ear的包重复jar都会调入jboss内部,而造成浪费过多地的服务器资源,会出现不定期的异常。

2:jboss eap 6.*系列,需要模块化配置,需要加载的jar,解决如何在jboss里面配置

3:公共的jar在jboss里面已经配置,加载……但是源码运行的时候不能根据maven的配置,加载jar的路径的问题

第一步:配置模块

配置mysql和oracle驱动的方式,详情看我的博客不在重复

我们现在把相关的spring的公共的jar、shiro等等抽取到jboss模块中配置,在自己的jboss下的modules模块中,添加相关的jar的配置即可

Center

第二步:需要在每一条线的war\core\parent的pom文件对jar的依赖添加

  1. <scope>provided</scope>

这句话的意思就是在我们开发、编译的时候会加载jar,在打包的时候不会打入到ear包内部,而会自动通过容器提供的jar来加载

如下

War修改

  1. <dependency>
  2. <groupId>org.springframework</groupId>
  3. <artifactId>spring-webmvc</artifactId>
  4. <scope>provided</scope>
  5. </dependency>
  6. <dependency>
  7. <groupId>commons-lang</groupId>
  8. <artifactId>commons-lang</artifactId>
  9. <version>2.6</version>
  10. <scope>provided</scope>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.apache.shiro</groupId>
  14. <artifactId>shiro-cas</artifactId>
  15. <version>${shiro.version}</version>
  16. <scope>provided</scope>
  17. </dependency>
  18. <dependency>
  19. <groupId>net.sf.ehcache</groupId>
  20. <artifactId>ehcache-core</artifactId>
  21. <version>${ehcache.version}</version>
  22. <scope>provided</scope>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.jasig.cas.client</groupId>
  26. <artifactId>cas-client-core</artifactId>
  27. <version>${cas.version}</version>
  28. <scope>provided</scope>
  29. </dependency>
  30. <dependency>
  31. <groupId>commons-fileupload</groupId>
  32. <artifactId>commons-fileupload</artifactId>
  33. <version>1.3.1</version>
  34. <scope>provided</scope>
  35. </dependency>

每个系统的parent的pom文件,修改完组长记得deploy一份

  1. <dependency>
  2. <groupId>org.hibernate</groupId>
  3. <artifactId>hibernate-core</artifactId>
  4. <version>${hibernate.version}</version>
  5. <scope>provided</scope>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.codehaus.jackson</groupId>
  9. <artifactId>jackson-mapper-asl</artifactId>
  10. <version>1.9.13</version>
  11. <scope>provided</scope>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.springframework</groupId>
  15. <artifactId>spring-webmvc</artifactId>
  16. <version>${spring.version}</version>
  17. <scope>provided</scope>
  18. </dependency>
  19. <dependency>
  20. <groupId>javax</groupId>
  21. <artifactId>javaee-api</artifactId>
  22. <version>${javaee-api.version}</version>
  23. <scope>provided</scope>
  24. </dependency>

第三步:ear中添加对jar包的路径的加载配置,修改ear中的jboss-deployment-structure.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <jboss-deployment-structure>
  3. <sub-deployment name="itoo-authority-role-web-0.0.1-SNAPSHOT.war">
  4. <dependencies>
  5. <module name="org.jboss.xnio"/>
  6. <module name="org.apache.shiro">
  7. <imports>
  8. <include path="META-INF**"/>
  9. <include path="org**"/>
  10. </imports>
  11. </module>
  12. <module name="org.jasig.cas.client">
  13. <imports>
  14. <include path="META-INF**"/>
  15. <include path="org**"/>
  16. </imports>
  17. </module>
  18. <module name="org.springframework.data">
  19. <imports>
  20. <include path="META-INF**"/>
  21. <include path="org**"/>
  22. </imports>
  23. </module>
  24. <module name="org.crazycake">
  25. <imports>
  26. <include path="META-INF**"/>
  27. <include path="org**"/>
  28. </imports>
  29. </module>
  30. <module name="commons-fileupload">
  31. <imports>
  32. <include path="META-INF**"/>
  33. <include path="org**"/>
  34. </imports>
  35. </module>
  36. <module name="org.codehaus.jackson">
  37. <imports>
  38. <include path="META-INF**"/>
  39. <include path="org**"/>
  40. </imports>
  41. </module>
  42. <module name="redis.clients">
  43. <imports>
  44. <include path="META-INF**"/>
  45. <include path="org**"/>
  46. </imports>
  47. </module>
  48. <module name="org.apache.commons.commons-pool2">
  49. <imports>
  50. <include path="META-INF**"/>
  51. <include path="org**"/>
  52. </imports>
  53. </module>
  54. <module name="org.springframework">
  55. <imports>
  56. <include path="META-INF**"/>
  57. <include path="org**"/>
  58. </imports>
  59. </module>
  60. </dependencies>
  61. </sub-deployment>
  62. </jboss-deployment-structure>

第四步

这样的话,我们大部分的公共的jar都不会打入到ear包中,现在的测试的ear经过咱们整合之后,会在6M左右

总结

整个解决问题的过程中,更多的是查找英文资料和文档,相信解决问题的办法总比困难多……

发表评论

表情:
评论列表 (有 0 条评论,1061人围观)

还没有评论,来说两句吧...

相关阅读

    相关 JBoss EAP 6.1部署SSO

    原来开发时,SSO的war是部署在Tomcat上,现在需要迁移到JBoss。 JBoss在Linux上的安装很简单,直接解压即可运行。 因为项目使用的是JDK7,先安装JD