JBoss 7 project libraries as a module

泄露秘密 提交于 2019-12-24 02:23:21

问题


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.

So, I have, for example:

<dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>5.0.0</version>
        </dependency>

I want to add "provided" to that dependency, and keep the JAR in JBoss, without including it in my war.

How?

PS: I know that it will be available to all deployed applications. It's good.


回答1:


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.

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:

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).

In this folder, create a folder main.

Put the library jar into the main folder.

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.

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.



来源:https://stackoverflow.com/questions/14852144/jboss-7-project-libraries-as-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!