How to add libraries to Wildfly Application Server using module? - jboss

I want to load the Application server Libraries in Java Build Path in Eclipse,
I have 5 applications in Eclipse which shares common libraries,
I can't put all the libraries in each project lib folder,
so i want to add the libraries in Wildfly Application server using modules.
This is my module.xml file add added the lib at WILDFLY_HOME/modules/system/layers/base/com/mysql/main/mysql-connector-java-5.1.23-bin.jar
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.23-bin.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.transaction.api" />
</dependencies>
</module>
After Restarting the server, this module is not loading in Eclipse Build path.
Can any one knows what wrong with this modules ?
In Wildfly I have some predefined modules, those are loading in build path successfully, but user-defined modules are not loading ?
Why ?

Solution found:
Follow below steps :
Go To Eclipse > preferences > Server > Runtime Environments > Default Classpath Entries
Select "Wildfly 8.x Runtime" and add a module
and click on apply, now rebuild your application and check,
the library will be added in buildpath by module name.

Related

Possibility to access wildfly / app server libraries via jboss-deployment-structure.xml?

I have a web application running on a wildfly app server (22.X). It contains a war file which has the ability (besides the actual functionality) to query the wildfly itself for its active running sessions via JMX and display that number on an simple html page.
Originally the following dependency was added (via maven) to make this work:
<dependency>
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
<version>3.0.4.Final</version>
However this dependency brings lots of other transitive dependencies along like jboss-marshalling, xnio, jboss-threads, wildfly-*, (...) - all packages which does exist within the wildfly app server anyway. So I was wondering whether it is possible to use those app server packages instead of bundling it as part of the war. I tried to add the following to the jboss-deployment-structure.xml to the EAR:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<deployment>
<dependencies>
<system export="true">
<paths>
<path name="sun/reflect"/>
</paths>
</system>
</dependencies>
</deployment>
<sub-deployment name="service.war">
<dependencies>
<module name="org.jboss.remoting3.remoting-jmx" services="import"/>
</dependencies>
</sub-deployment>
However it didn't work - as soon as the dependencies were removed from the war file it stopped working. My question:
Is it possible to specify/configure the deployment structure file to allow access to the necessary packages from the application server? (I know that this is a wildfly specific solution but this is intended)
It looks like this module has moved to org.jboss.remoting-jmx. The org.jboss.remoting3.remoting-jmx does export the org.jboss.remoting-jmx module in WildFly 22, however the services are not exported which could be the issue.
Either way, it's best to use the org.jboss.remoting-jmx.

How can you add "." as a resource-root to a module using jboss-cli?

Not sure there's a way to do what I want with jboss-cli, so looking for confirmation.
If I connect to EAP using jboss-cli and run this command to add a module:
[standalone#localhost:9999 /] module add --name="test" --resources="."
Failed to locate C:\EAP-6.4.0\bin\"."
The module add command should create a module.xml with the following element:
<module xmlns="urn:jboss:module:1.1" name="test">
<resources>
<resource-root path="."/>
</resources>
<dependencies>
According to module add --help, it looks like the command expects a physical resource to copy into the directory where module.xml is created:
--resources - (used with add, required unless module-xml is used) a list of
filesystem paths (usually jar files) separated by a
filesystem-specific path separator, i.e.
java.io.File.pathSeparatorChar. The file(s) specified will be
copied to the created module's directory.
The description seems to match the behaviour, so just looking for confirmation that there isn't a "jboss-cli" way, before resorting to sed.
Thanks.
On JBoss EAP 7.2 (and likely on other versions of JBoss too), it is possible to do this by creating the module.xml file in advance and using "module add" with the --module-xml option to explicitly specify the module.xml file.
Here is an example which creates a module consisting of a single properties file, creates the module.xml file, and then adds the module to JBoss:
% mkdir /tmp/module-src
% cd /tmp/module-src
% echo hello=bonjour > example.properties
% cat > module.xml
<module xmlns="urn:jboss:module:1.1" name="test">
<resources>
<resource-root path="."/>
</resources>
<dependencies>
% jboss-cli.sh --command="module add --resources=example.properties --module-xml=module.xml --name=test"
This creates the module directory, copies the module file (with resource-root path=".") into the module directory, and copies the specified resource(s) into the module directory.

class def not found in jboss as 7.X

I have a project structure as
eardirectory.Ear
lib/
my-custom-classes.jar
.....
.....
my-custom-ejb.jar
META-INF/
....
//Now I tried to load classes from classloader as
ClassLoader cl = Thread.currentThread().getContextClassLoader();
clazz = Class.forName(my-custom-classes.class1.class.getName(), true, cl);
but this will not work as current thread is of jboss and jboss has not any identification of my-custom-classes.jar.So my question is how this can be done with jboss? I have to have to load class definition at runtime.
Is there any way in "jboss-deployment-structure" I can define how to load classes before deploying EAR?
Follow the steps to create module it should work
Step-1
In jboss-as-7.1.1.Final/modules/com/company/gyani/main/
-module.xml
-my-custom-classes.jar
Content of module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.company.gyani">
<resources>
<resource-root path="my-custom-classes.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Step-2 Now IN my.ear/META-INF/
-jboss-deployment-structure.xml
-MANIFEST.MF
Content of MANIFEST.MF
Manifest-Version: 1.0
Dependencies: com.company.gyani
You need to use concept of module(s) provided by JBoss AS7.
Here you configure your classes/jars/property files as modules and these are loaded while starting JBoss at server scope and are accessible to any deployed application that carries a dependency on this module.
Read through How to configure module

JBoss AS 7.1 - how to include all in module.xml when creating modules

I have to create a module for Spring framework - org.springframework. There are many jars, is there a way to say: include all jars in this org/springframework/main/ folder? Something like below.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="nuance.classes">
<resources>
<resource-root path="./*"/>
</resources>
</module>
the above seems doesn't work though. Any guide/document available for this?
The documentation for the module system and classloader is here.
I don't know if you can specify all JARs in a wildcard, but you shouldn't. Many of those JARs will be for libraries and APIs already packaged by JBoss AS 7. You can just declare a dependency on them, and unless you need a different and incompatible version you should do so rather than packing another copy of the jar.
You'll probably find that once you cut out the stuff that's already packaged or part of the standard APIs, you won't have much to package. Take this EclipseLink module for example; it ended up boiling down to nothing but the EclipseLink jar its self. (The ${ECLIPSELINK_JAR_NAME} is because this project produces an EclipseLink module as part of its build process; the final module.xml contains the real name of the jar).
For future reference (it's been years from the question), I'm using the following code:
<?xml version="1.0"?>
<module xmlns="urn:jboss:module:1.0" name="nuance.classes">
<resources>
<resource-root path="." />
</resources>
</module>

How to debug a incorrect module dependency in JBoss AS 7?

I have a web app, which uses Sun's MSV library. All the classes for MSV are included in jars in the web app WEB-INF/lib. When deploying this app on JBoss 7, I get the following exception:
java.lang.NoClassDefFoundError: Could not initialize class com.sun.msv.datatype.xsd.AnyURIType
at com.sun.msv.datatype.xsd.DatatypeFactory.getTypeByName(DatatypeFactory.java:195)
at com.sun.msv.datatype.xsd.ngimpl.DataTypeLibraryImpl.getType(DataTypeLibraryImpl.java:32)
at com.sun.msv.datatype.xsd.ngimpl.DataTypeLibraryImpl.createDatatypeBuilder(DataTypeLibraryImpl.java:36)
at com.sun.msv.reader.trex.ng.DataState.startSelf(DataState.java:58)
at com.sun.msv.reader.State.init(State.java:153)
at com.sun.msv.reader.GrammarReader.pushState(GrammarReader.java:576)
at com.sun.msv.reader.SimpleState.startElement(SimpleState.java:71)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.msv.reader.trex.TREXBaseReader.startElement(TREXBaseReader.java:184)
at com.sun.msv.reader.trex.ng.RELAXNGReader.startElement(RELAXNGReader.java:524)
at com.sun.msv.reader.trex.ng.comp.RELAXNGCompReader.startElement(RELAXNGCompReader.java:197)
at orbeon.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:497)
at orbeon.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180)
at orbeon.apache.xerces.xinclude.XIncludeHandler.emptyElement(XIncludeHandler.java:1024)
at orbeon.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:275)
at orbeon.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1654)
at orbeon.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
at orbeon.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:845)
at orbeon.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:768)
at orbeon.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
at orbeon.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1201)
at com.sun.msv.reader.util.GrammarLoader._loadSchema(GrammarLoader.java:514)
at com.sun.msv.reader.util.GrammarLoader.parse(GrammarLoader.java:325)
at com.sun.msv.reader.util.GrammarLoader.loadSchema(GrammarLoader.java:189)
at com.sun.msv.verifier.jarv.TheFactoryImpl.parse(TheFactoryImpl.java:42)
at com.sun.msv.verifier.jarv.FactoryImpl.compileSchema(FactoryImpl.java:98)
It complains that it cannot find the class com.sun.msv.datatype.xsd.AnyURIType, but that class is present in one of the jars. I am assuming some of those classes on the stack trace were "incorrectly" picked up from a module that comes from JBoss, thus loaded from another class loader, rather than from a jar in the web app's WEB-INF/lib. But which one can it be? (The orbeon.apache.xerces you see there is a re-rooted version of Apache Xerces, so we can be sure it has been loaded from the web app jars.) I have seen that I can exclude some modules in the jboss-deployment-structure.xml, as follows, but which on should I exclude? How to find out?
<jboss-deployment-structure>
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<deployment>
<exclusions>
<module name="com.sun.xml.bind"/>
<module name="org.codehaus.woodstox"/>
<module name="org.codehaus.jackson.jackson-xc"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
HI I am not understanding your actual configuration but this is because of your module configuration in xml configuration file. I also got this kind of error but i resolved it by provided module to server.So You have to install your library as a module in your server.
Add a module
i.Under the root directory of the application server, is a directory called modules. Create your own module
For E.g. jboss-7.0.0./modules/com/mysql/main
ii. Now you need to define your module with a module.xml file, and the actual jar file that contains your database driver in the created folder.
Modules
+---com
¦ +---codehaus
¦ ¦ +---main
¦ ¦ +-------module.xml
¦ ¦ +------<your jar file>
The contents of module.xml should be as follows:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="<*module name*>">
<resources>
<resource-root path="<*jar name*>"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Dependencies are used for declaring your module dependencies on other module.