JBoss 7项目库作为模块 [英] JBoss 7 project libraries as a module
问题描述
我的项目之战,在添加了一些Maven依赖项之后,大小增加到32MB!
My project's war, after adding some maven dependencies, increased in size to 32MB!
我需要缩小尺寸.我四处搜寻,发现可以使用模块.
I need to reduce that size. Gooogling around I found that using modules could be the way.
最佳做法是什么?将每个库添加为新模块?创建带有所有库"的模块?我什至不知道那是不可能的.
What's the best practice? Adding each library as a new module? Creating a module with "all libraries" ? I don't even know if that's possible.
例如,我有:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.0.0</version>
</dependency>
我想在该依赖项中添加"提供",并将JAR保留在JBoss中,而不必在我的战争中加入它.
I want to add "provided" to that dependency, and keep the JAR in JBoss, without including it in my war.
如何?
PS:我知道它将对所有已部署的应用程序可用.很好.
PS: I know that it will be available to all deployed applications. It's good.
推荐答案
从我的库中分离应用程序对我来说不是一个好主意-您正在极大地增加应用程序的上下文依赖性,并且将无法在该应用程序上部署该应用程序另一台不修改内部结构的服务器.在生产环境中,这可能是不可能的.
Separating the application from it's libraries does not sound like a good idea to me - you are dramatically increasing the application's context dependency and will be unable to deploy the application on another server without tinkering with it's internals first. This might not be possible/allowed in a production environment.
32MB的war
...怎么办?如今,再多几个MB并不是一个真正的问题.带有几个hunderds MB的业务应用程序并不罕见.
A war
of 32MB...so what? A couple extra MB is not a real problem nowadays. A business application weighing in with a couple of hunderds MB is not so rare.
因此,在发出严厉警告之后,可以这样做:
So, after a stern warning, this is how it could be done:
转到JBOSS_HOME/modules
目录并为工件坐标创建目录层次结构(com.example依赖项位于/com/example/文件夹中).
Go to the JBOSS_HOME/modules
directory and create a directory hierarchy for the artifact coordinates (an com.example dependency would sit in the /com/example/ folder).
在此文件夹中,创建一个文件夹main
.
In this folder, create a folder main
.
将库jar
放入主文件夹中.
创建一个module.xml
文件并填充它:
Create a module.xml
file and fill it:
<module xmlns="urn:jboss:module:1.1" name="com.example">
<resources>
<resource-root path="mylib.jar"/>
</resources>
</module>
我不确定是否需要重新启动服务器.
I am not sure if restarting the server is necessary.
如果您的模块具有自己的依赖关系,则可以通过在module
元素中添加类似的内容来声明它们:
In case your module has it's own dependencies, you can announce them by adding sth like this into the module
element:
<dependencies>
<module name="com.example.implementation"/>
</dependencies>
我建议将每个库都部署在其自己的模块中,以实现模块化(如名称所示;).然后,您可以单独交换它们.
I would advise to deploy each of the libraries in it's own module for (like the name suggests ;) modularity. You could then exchange them individually.
这篇关于JBoss 7项目库作为模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!