When do modules specified in jboss deployment structure load? At jboss startup or when classes in jars within modules are called ?
Module jar files will be loaded into memory while deploying application, but i think class object is initialized when its called.
Related
I have created and deployed one war for my application.
I wanted to use derby for integration testing so I created one module in Jboss.
At run time I am getting ClassCastException for same class, since the class is getting loaded twice: first from war, then from my module's jar.
To elaborate, my war, say application.war contains myderby.jar and under my module i have added myderby.jar .My class, say Custom.java, is present in myderby.jar.
If you want a jar to be accessible to multiple WARs, JARs, or an EAR and a WAR/JAR - or in fact any such combination, you can include it as a global module. Here's how it can be done.
This might also help.
As Suggested I followed the following link
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Administration_and_Configuration_Guide/Add_a_module_to_all_deployments.html and it worked for me.
I have an EAR installed in eclipse on WLP 8.5.5.3
This is the EAR entry with a classloader attached:
<enterpriseApplication id="App4EAR" location="App4EAR-4.1.5-SNAPSHOT.ear" name="App4EAR">
<classloader apiTypeVisibility="spec,ibm-api,api" delegation="parentFirst" commonLibraryRef="baseLibraries.app4">
</classloader>
</enterpriseApplication>
The server is starting without issues. The first jsp page in the application tries to read a properties file which is located in the WAR component. This is where it fails.
SRVE0777E: Exception thrown by application class 'java.util.ResourceBundle.throwMissingResourceException:1427'
java.util.MissingResourceException: Can't find bundle for base name prop.appadmin, locale nl_BE
The object that reads the properties is located in the web application together with the properties file. The utility class for reading the resource bundle is in a separate jar and is part of a shared library (baseLibraries.app4).
This is an entry from the App4EAR.ear.xml deployment definition that points to folder where the properties file is located:
<dir sourceOnDisk="C:\svn\app4\App4Web\target\classes" targetInArchive="/WEB-INF/classes"/>
When using java.util.ResourceBundle() directly in the application it successfully locates the properties file. But not so when we use the utility class from the shared library.
Why is a shared library not able to access properties resources in the main web application?
Your shared library is loaded in parent classloader, and the classes and also properties in your application are not visible to that classloader thats why they cannot be found. Add property files to the classpath of the library instead of web app.
Packaging the utility jar, that accesses the resource file, in the web application solves the problem.
This solution kind of negates the purpose of shared libraries. Also note that on WAS 8.5 this was not a problem, so something did change in the way shared libraries are exposed/loaded.
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
I am having an issue with a 3rd party developer.
They have provided a number of jars, and unfortunately in 2 different jars they have different implementations of a class (same name, same package).
We deploy using a single war file where both jars (among many others) are packaged together in web-inf/lib directory and unfortunately both jars are needed.
Is there a way where I can guarantee in JBoss eap 6 that the class from a.jar gets loaded before the class from b.jar?
Thanks.
All of your answers about classloading on JBoss can be found here at this link. But since now I advise you to read the "JBoss Deployment Structure File" section
With the "jboss-deployment-structure.xml" JBoss specific deployment descriptor you can control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments). It can do the following:
Prevent automatic dependencies from being added
Add additional dependencies
Define additional modules
Change an EAR deployments isolated class loading behaviour
Add additional resource roots to a module
I am developing a Java EE 6 bottom-up JAX-WS to expose an EJB3.1 stateless session bean. The web service in a WAR is failing to install on deployment because it references an external jar (or shared library) which one can assume is not loaded yet.
The common suggestion is to include the jars in the /lib folder, which does fix the issue, however the jars need to remain in this external shared library location and NOT in the ear file, because they amount to 30MB.
What are some techniques to get around this issue in a Websphere (WAS v.8) environment or any server environment.
Some suggestions I have found include:
1. define classpath in META-INF file.
2. define the resources in deployment.xml
3. alter class loading order
4. (from ibm) In the case where the jars are part of a Shared Library configured on WebSphere Application Server, then a User Library must be used to configure the project for development before generating the WebService.
However, I have been unsuccessful to find any help online in these areas. Is there another technique or does anyone know anything about accomplishing this? Thanks in advance.
EDIT: If I specify the libraries in the META-INF using class-path, they are loaded before extensions, shared libraries..etc, but they are still loaded after the WAR which is not good. Again, this isn't a runtime issue because the web services are created at deployment on the fly.
I submitted a ticket to IBM. The libraries referenced by the web service are needed during deployment and must be bundled into the Ear in some fashion. I threw them in the web-inf/lib folder. However, if the referenced libraries then depend on additional libraries, these can be placed in the Shared Libraries. Seems odd to me too, but let's all just admit "shared libraries" are a hack anyways.
If you still have issues, just make sure your class loading is set to parent_last.