Share module across all modules of wildfly - jboss

Add custom module dependency across all the system/layer/base jboss modules and all custom modules.
I have added the module dependency in <global-modules/> in standalone-full.xml but I guess its only for custom modules as I need to add it manually in module.xml of all the system/layer/base module.
Is there a way to expose one module to all modules?

Related

In Wildfly, is there a difference between including a JAR file in my WAR as opposed to linking to it via jboss-deployment-structure.xml?

I'm using Wildfly 11 with Java 8. If I deploy two WAR files with identical libraries
/WEB-INF/lib/javassist-3.18.1-GA.jar
Is there any advantage to including these libraries in the /WEB-INF/jboss-deployment-structure.xml like so
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
...
<module name="org.javassist" />
as opposed to including the JAR in my WAR files? That is, do I cut down on memory due to class loading or any similar advantage?
More than any advantage in memory or performance (that JBoss modules claims it can do), i think JBoss modules are more for take advantage of reuse of modules, or separate versions of the same module.
If you check the structure of the JBoss modules in file system, it remembers maven repository style, in this way you can review more easily the modules and versions available, or you can check the dependencies with the same tools of JBoss AS, as CLI or the Web console.
If you have an application and you can't scale a version of a specific framework/library you can stay with it, and you can have other applications with other versions of the same library. I know you can reach the same when you embed your jars into your application, but you have to do the same thing in all of your apps, with JBoss modules you just have to declare your dependencies and your application will be more lightweight.
In JBoss modules every jar you configure are a module, and every module has its own class loader(modular class loader), and every class loader knows exactly what classes it has to load (and its dependencies if apply), against a flat class loader (hierarchical), that loads all classes. This architecture makes JBoss modules faster (basically because is a new way to do the same thing of its ancestor, the JDK class loader).
In this link, you can check a more specific guide of JBoss modules that explains more concepts and surely has a better explanation.
In this link, you can find a short review and a pair of examples.
Hope this helps.

Best practice to dependency resolve in Jboss EAP

In case of war file deployment, there are two possible ways to resolve dependency in Jboss EAP:
we could keep all the dependent jar files in Jboss modules and get access of them using jboss-deployment-structure.xml file.
we could keep all the jar files in WEB-INF/lib folder inside war file.
Which one is the best practice to follow and why?
It depends on what you prefer.
#1 means you need to configure server and application(s), and this is more effective when you have more applications on server using these modules as dependencies. So you save space from duplicating libraries in more applications.
#2 means you have almost all dependencies in your deployment application => bigger file/directory (but don't forget some dependencies are automatically enabled by container based on what you use Servlets, JPA etc.).

Having a jboss-deployment-structure.xml with dependencies in common libraries

I have a small issue that is annoying me somewhat. We have built numerous commons libraries for all our applications deployed on JBoss/Wildfly. Some of those common libraries have dependencies to JBoss modules.
The common way for EAR and WAR files is to add a jboss-deployment-structure.xml to the archive, which contains a bunch of module-dependencies.
I have tried several times to add a jboss-deployment-structure.xml to my Commons JARs so that the WAR/EAR-archives that import them will automatically see the dependencies the JAR has as it's own, however, no attempt of doing this renders the correct result.
Has anyone successfully managed to declare "transitive" dependencies in JAR-files packed inside of WAR-files without having to redeclare the same dependencies in the WAR-file's jboss-deployment-structure.xml?
Any examples would be greatly appreciated!
You can use the MANIFEST.MF to declare dependencies for a JAR. The line will look something like:
Dependencies: org.some.module, org.another.module
The Maven plugin maven-jar-plugin will add it for you as part of the build process.
Your best option is to create your own JBoss module to hold all your common JARs used by all your different applications. This module would have it's own module.xml file declaring the dependencies on the JARs contained within it and one any libraries on other JBoss modules. These custom modules can also be versioned and applications can also depend on specific versions.

JBOSS AS 7 custom class loader not working

We recently moved to JBOSS AS 7.Since it is based on OSGi and all modules are isolated, we are having a problem.
One of our jars is loaded by a URLclassloader from a specified directory outside of the JBOSS modules.
Class[] parameters = new Class[]{URL.class};
URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL",parameters);
method.setAccessible(true);
method.invoke(sysloader,new Object[]{ flist[i].toURI().toURL()});
flist[i] contains the jar with complete path to be loaded.
Where as this used to work previously, after AS 7, this class is not getting loaded.
I know you can add these jars to the modules folder and specify dependency. But we want this to work.
Is there a solution for this?
As others have said, JBoss AS 7 is not based on OSGi, it uses its own module system (JBoss Modules). What you're doing (reflection on classloaders) is against any rules, totally unsupported and worked only by accident. You you should is the following:
create a JBoss module for your JAR (the link is for a database module but should work with any JAR)
use jboss-deployment-structure.xml to reference that module

Is it possible to have a dependency on a JAR file in a NetBeans module project?

I have created a NetBeans module project and need to add a dependency on a JAR file I have created- is this possible? I only see the option to add a dependency on a nother module. I am using NetBeans 6.5.1.
THANKS!
Modules can only depend on other modules.
Create Library that references your class, then create a "Library Wrapper Module" that encapsulates the library as a module.