I have two Cluster in my Netbeans RCP project (Cluster A, and Cluster B).
Module M-A in Cluster A, has dependency to Module M-B in Cluster B. M-A ---> M-B
besides this, both modules (M-A and M-B) have dependency to a third party jar ( tp.jar ).
when i'm building my suite, I have tp.jar in 2 different places (two cluster) :
A/modules/ext/tp.jar and B/modules/ext/tp.jar
in consequence netbeans class loader finding 2 jar files in the class and is not able to load the any of them.
Any idea have to solve this issue ?
PS: I'm using Maven 2.X. and nbm plugin.
Regards,
Mohammad
You can create a wrapper module for your library (tp.jar) and let both modules depend on the wrapper module.
You can read more about it at http://wiki.netbeans.org/DevFaqWrapperModules
Related
I have an OSGi setup with maven.
The parent bundle's pom.xml has a dependency on JAR A which is in turn dependant on JAR B(version 1).
The parent has 2 children bundles. Child bundle 1 uses JAR B with version 1.
Child bundle 2 requires JAR B with version 2.
The JARs are not backward compatible. So I cannot upgrade the version of JAR B from 1 to 2.
I need to use version 1 of JAR in bundle 1 and version 2 of the same JAR in bundle 2, without any errors in class loading.
Right now, I get an error in class loading where any one of the bundles fail due to NoClassDefFound error because of using 2 versions.
How do I resolve this dependency using OSGi?
One of the advantages with OSGi (arguably the most important one) is that you can use different versions of the same library in different bundles. In the few cases where that's a problem you would either get a 'loader constraint violation' or a 'ClassCastException'. The OSGi troubleshooting doc for the Vespa search engine shows a few examples. This would happen if one of your bundles calls an api in another bundle involving the classes in JAR B (as argument or return value), and the two bundles use different versions of B.
In your case, the problem is that either the failing bundle is missing an Import-Package, and/or there is no bundle exporting the required version of the package with the missing class. You can examine the bundles' manifest.mf to verify.
The simplest and safest way to solve this is to embed the desired version of B into each of your child bundles. This way, your child bundles will use their own version of B, living in separate class loaders.
You don't mention how you package your bundles, but if you're using the maven-bundle-plugin, it has an Embed-Dependency config option. Please note that you also have to embed the transitive dependencies of B by using the Embed-Transitive directive to ensure that all code used inside B is available at runtime.
Another solution is possible if both versions of B are packaged as OSGi bundles, and each exports the package (of the missing class) with a unique version number. (Again, verify from looking at B's manifest.mf). Then, you can deploy both B bundles, and have each of your child bundles import the correct version.
I have a problem when deploying two ear files in Jboss 7 and would be thankful for your help.
Following scenario:
EAR 1 contains EJBs which are looked up by EAR 2 (also) at server startup. Thus, EAR 1 has to be deployed before EAR 2 (via jboss-deployment-structure.xml dependency settings).
Right after being deployed, EAR 1 also needs access to classes contained in EAR 2 because of Hibernate and JNDI related class loading (among others).
But as EAR 2 isn't deployed at that time, there's a need for EAR 1 to contain a client-jar file of EAR 2.
Now, the problem is that in the course of EAR 1 and EAR 2 configuration (at server startup) ClassCastExceptions occur because...
(non-EJB) Java object obj1, whose class C was loaded by the classloader of EAR 1, is bound in JNDI
and after being looked up, supposed to be cast to object obj2 whose class C was loaded by the classloader of EAR 2
Now I wonder, if there's a possibility that these common classes of EAR 1 and EAR 2 are being loaded with the same classloader in JBoss 7. I already tried to put them in a server module, which didn't work out.
Thanks a lot for your help in advance!
PS: I'm aware of the poor design declared above. But due to restrictions, I have to follow up on it.
To avoid class cast exceptions, the common libraries need to be put in a classloader that is common to all applications in the two EARs, and no other copies of those libraries should exist in each application.
If it's an option to use only one EAR instead of two, put all the WARs inside a single EAR, remove the common classes from the WARs and put them on the EAR library folder.
This will associate the common classes to the EAR classloader, which is common to all the applications running inside a EAR, so that would solve the problem.
If you must use two EARS, then the common classes need to be put in a classloader at the level of the server shared by all applications.
JBoss 7 is an OSGI based container that allows to create an isolated module with a few jars and link it to an application. So if you try this:
create a module with the common library AND it's dependencies, see instructions here
link the module to all applications
remove the copies of those libraries from all applications and leave them only at the module
It will work fine, but don't forget to put the dependencies of the common library in the module as well otherwise it will not work, the dependencies need to be visible at the level of the module, and there can be no duplicate jars between module and applications (otherwise class cast exceptions might happen).
Another way far less recommendable but it would also work, is to put the common classes at the level of the common classloader, see this diagram. The common classloader folder is located at $CATALINA_HOME/lib (Jboss is based internally on Tomcat).
Specially if there are other applications running in that server don't try the second option. It could help to have a look at a tool I built for these type of issues, JHades.
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
In Dependencies tab, I have a choice between plug-ins and packages.
What's the difference between them? For org.eclipse.compare, I have it in imported package and also in plug-ins.
I find the jar file in plugins directory, but I don't know where the package file of org.eclipse.compare is located.
In the export menu, it seems like that there seems to be only exporting to jar, not exporting a plugin or packages. How can I export packages?
ADDED
Based on this post - How to import a package from Eclipse? and shiplu's answer. This is what I came to understand. Please correct me if I'm wrong.
In eclipse, when I use come external class, I can use Quick-Assistant or Organize imports (Ctrl-Shift-O) to resolve the reference. Eclipse adds the package that contains the class in Imported Packages for the project that I'm working on. A package can contain multiple classes (types). Eclipse understands what plugin contains the package, and resolve the reference issues.
A plug-in (jar file) can contain multiple packages. By specifying a required plug-ins in the dependencies tab, we can reference all the packages (and classes in the packages) for all the java projects in the eclipse IDE.
And from my experience, I had to add all the dependencies in order to make headless RCP standalone (http://prosseek.blogspot.com/2012/12/headless-rcp-standalone.html).
An Eclipse plug-in is basically an OSGi bundle with additional plugin.xml file which Eclipse IDE understands and interprets.
So the answer to your question lies in the OSGi specification and the OSGi programming model, since, very simply put, Eclipse is an Application running on implementation of OSGi called Equinox.
OSGi is all about having modular applications and so it defines several levels of modularity.
One such level is a bundle-level (module-level) modularity and more fine grained level is the package level modularity.
So you can have your OSGi application (a set of bundles; eclipse is just that) which consists of db-bundle (which provides data store services), app-domain-bundle (which provides your application domain services) and remote-bundle (which exposes to the web your application via REST for example).
And then you say remote-bundle depends on domain-bundle which depends on db-bundle.
Which is all good, but cripples the inherent modularity OSGi provides, because you are basically restricting your application to specific implementations of db-bundle and remote-bundle i.e. to specific implementations of the services they provide.
Instead, you can establish the above dependencies not between bundles but between packages i.e. establish a service-level dependencies.
Then you say domain-bundle requires dbstore.service package to run, it doesn't care which bundle provides it it just needs an instance of this service to be able to work. So you can have multiple bundles providing implementations of the dbstore.service, and the domain-bundle can pick and choose at runtime what service to use.
It is really hard to explain OSGi concepts in just a several sentences, I'd really suggest you dig around the web on this and maybe even have a look at the OSGi specification.
Another way to explain it is to say that bundle/plug-in is a jar file with specific structure and metadata descriptors (MANIFEST.MF and plugin.xml), which describe its contents in Java language concepts - which java packages and services this specific jar contains and will expose to the OSGi runtime so that they can be consumed by other bundles. I.e. the bundle is the physical deployable entity while the descriptors are metadata about what actually is being deployed.
EDIT:
Package or Service-level dependencies also have some drawbacks, as Lii points out in the comments below, the main one being that it adds complexity and dynamics to the dependency model. Have a look at her or his comment below - it is worth reading!
You use Imported Packages when you want to use a specific package but do not care which plugin provides it. OSGI will choose one for you.
Eclipse plugins is something like extension to the IDE itself. But imported packages are actually packages that you'll use in your current project.
One is for development IDE another is for the project you are coding.
I have this third party framework which comes with a huge set of dependent libraries, which by the way, have not yet been indexed in any Maven repository. I want to use this framework with some Web Apps, but for obvious reasons I don't want to put all those libraries under WEB-INF/lib, neither do I want just to place them all under server/default/lib to avoid mixing them with other local and third party libraries.
Is there some way under JBoss 4.2.2 or higher to specify a custom lib directory for certain Web Apps? It's possible and/or advisable to have something like server/default/lib/myAppLib?
Any suggestion on this regard?
You can add the following entry in your server/default/conf/jboss-service.xml for putting your jars in server/default/myLibDir:
<classpath codebase="myLibDir" archives="*"/>
To my knowledge, you have three options:
Package you WARs in an EAR and move the library JARs out of WEB-INF/lib and
place them in a lib folder at the root of the EAR. No extra configuration required. This (non portable) solution is described in Configuring JBoss shared libs.
Move the library JARs out of WEB-INF/lib and place them into server/xxx/lib.
Deploy the JARs in the deploy/ folder and disable WAR file class loader isolation.
I don't recommend option #3. Option #2 is what you don't want. This leaves us with option #1 (which is IMO the cleanest).
Related questions
Jboss shared library
In JBoss can I configure a “shared library” location?