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
Related
If I have an EJB packaged in a WAR because it is exposed as a REST web service, according to this link, I need to have the ejb-*.xml files at the root of the WEB-INF directory. My current environment is Websphere 8.5 and EJB 3.1
If I later add multiple EJBs ( in separate EJB projects ) in the same application and define its deployment descriptors in the respective projects, those seem to be ignored. It appears that ALL of my descriptors should be defined in the descriptors in the WEB-INF directory - or in other words, it seems that I should augment the descriptors in WEB-INF directory even for EJBs that are defined as separate projects.
Is this how it needs to be or am I missing something that is forcing me to do this? I could not find any documentation explaining this part.
More Details:
This is how my application.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd"
version="7">
<display-name>MyApp</display-name>
<module id="Module_1395346343165">
<web>
<web-uri>MyWeb.war</web-uri>
<context-root>myapp</context-root>
</web>
</module>
<module id="Module_1395346304194">
<ejb>ejb1.jar</ejb>
</module>
<module id="Module_1424684968934">
<ejb>ejb2.jar</ejb>
</module>
<module id="Module_1431010943758">
<ejb>ejb3.jar</ejb>
</module>
</application>
The ejb1 is the one that will live in the webapp. The other two, ejb2 and ejb3 are separate ejb projects that are supposed to be in EAR's root.
For EJBs in a WAR module, the files go in WEB-INF, so .ear!/MyWeb.war!/ejb-jar.xml, .ear!/MyWeb.war!/ibm-ejb-jar-bnd.xml, etc.
For EJBs in separator EJB modules outside a WAR, the files go in META-INF. So, .ear!/ejb1.jar!/META-INF/ejb-jar.xml, .ear!/ejb1.jar!/META-INF/ibm-ejb-jar-bnd.xml, etc.
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.
I deployed a simple OSGi test-bundle into JBoss 7.1.1 and try to dynamically instantiate the Jacorb ORB by doing
Class clazz = Class.forName("org.jacorb.orb.ORB");
All I got is
java.lang.ClassNotFoundException: org.jacorb.orb.ORB from [Module "deployment.test:1.0.0" from Service Module Loader]
What I already did:
in the JBoss configuration standalone.xml I added for the osgi-subsystem the capability <capability name="org.jacorb" startlevel="1"/>, so that the org.jacorb module is loaded. That already solved the problem, that the installation of my test bundle fails.
I declared the Dependencies-Descriptor on org.jacorb in my MANIFEST.MF (also tried with and without the export option): Dependencies: org.jacorb export
I added the jboss-deployment-structure.xml to my META-INF with the following content
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jacorb" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Also I did experiments with the ClassLoaders and realized, that the ContextClassLoader is null. But in the end, I cannot effect this as the non-test-code, because the Class.forName() cannot be changed to use a specific classloader.
So why do I get this ClassNotFoundException?
Thanks in advance
Alex
After hours of digging I did the puzzle ;-)
In standalone.xml/domain.xml JBoss configuration I added <capability name="org.jacorb" startlevel="1"/> in the <subsystem xmlns="urn:jboss:domain:osgi:1.2" activation="lazy"> section under <capabilities>
In the META-INF/MANIFEST.MF I added DynamicImport-Package: org.jacorb.orb to allow the classloader to dynamically extend the classpath during runtime
Set the context classloader by Thread.currentThread().setContextClassLoader(getClass().getClassLoader() that has been null before
If you have a normal OSGi bundle and it should see the org.jacorb.orb.ORB class,
then you should have:
1. ALL org.jacorb packages and subpackages have to be exported in the osgi framework.
2. Your bundle has to import ALL of the packages you use - e.g. with
"Import-Package:org.jacorb.orb"
Check that the versions are compatible.
Check that you import all packages and subpackages. Import of org.jacorb doesn't imply org.jacorb.orb.
If both conditions are satisfied, then the Bundle Classloader of your bundle should be able to see org.jacorb.orb.ORB.
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>
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.