8

Is there a way, we can deploy jars as a library/deployment in WildFly 10 like we can do it in weblogic server?. OR can we place the jars in any folder of server and define those dependencies as provided?

MDaniyal
  • 1,097
  • 3
  • 13
  • 29

2 Answers2

9

What I got the way to deploy jars on WildFly 10 server rather than making part of the war file is define below:

1) Put all your jars in wildfly\modules\system\layers\base\com\abcProject\main and place a file named module.xml with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.abcProject">
<resources>
    <resource-root path="aspectjrt-1.6.8.jar"/>
    <resource-root path="aspectjweaver-1.6.8.jar"/>
    <resource-root path="aopalliance-1.0.jar"/>
    <resource-root path="guava-18.0.jar"/>
</resources>

<dependencies>
    <module name="javaee.api"/>
    <module name="org.apache.commons.logging"/>
    <module name="org.jboss.vfs"/>
</dependencies>

Where resources are all those jars present in your abcProject/main folder and dependencies are all those jars on which your jars are dependent and are present in wildfly\modules\system\layers\base folders.

2) Then in your project add a file named jboss-deployment-structure.xml in WEB-INF folder with the following conents:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
    <dependencies>
        <module name="com.abcProject" >
            <imports>
                <include path="META-INF**"/>
                <include path="org**"/>
            </imports>
        </module>
    </dependencies>
</deployment>

3) Now set scope of all those dependencies in your pom files as provided that you have placed jars in abcProject/main folder.

That's all now run your project it will get all jars from server and will not include in war file during compilation.

MDaniyal
  • 1,097
  • 3
  • 13
  • 29
  • Are we sure this is an optimal answer? You can define modules in the deployment folders directly. I dont think it is optimal to add modules to the wildfly system folder, which is akin to adding jars to the JRE's lib folder. – Inquisitor Shm Aug 22 '17 at 13:09
  • But then can you define multiple modules in standalone deployment folder? Can you provide me a link for it's implementation? Thanks. – MDaniyal Aug 23 '17 at 11:05
2

To add external jars as a "library" in Jboss/Wildfly, you can define it as a module in your installation, or add it to an existing module.

See this link for more details on how to add a module in Wildfly.

Community
  • 1
  • 1
Leo G.
  • 458
  • 2
  • 10
  • Ok but then will I remove the all dependencies like spring etc or write it with provided scope? – MDaniyal Aug 24 '16 at 12:33
  • I actually want to make a war file of all my jars and deploy on server, can it be done? – MDaniyal Aug 24 '16 at 12:34
  • Yes, you can remove the dependencies from the EAR by specifiying a provided scope in the POM. I'm not sure about the global war file, you can however specify multiple jars in one jboss module (http://stackoverflow.com/questions/14745978/jboss-as7-how-to-create-module-xml-for-external-libraries) – Leo G. Aug 24 '16 at 13:38
  • Ok @Leo Thanks. I will try this approach too and will search for war module. – MDaniyal Aug 24 '16 at 13:48