I am interested in this question due to the problem I described here. How does Glassfish look for the required classes anyway? Suppose there are two libraries in pom.xml of the application (in dependencies), one is declared with scope provided, another is declared with standard scope.
Therefore, I have two libraries - A.jar is in Glassfish lib folder, B.jar is in WEB-INF/lib of the war module that I deploy.
What is the order of resolving the dependencies here? I assume that:
First look in the WEB-INF/lib folder if any jar matches the class.
After that look in Glassfish/lib folder if any jar matches the class.
Is that correct? Is the situation when class in A.jar refences a class in B.jar, legal for such a configuration, and vice versa?
To be more specific, I have Glassfish 2.1.
According to class loader documentation for GF2 I would say vice versa.
Note that the class loader hierarchy is not a Java inheritance hierarchy, but a delegation hierarchy. In the delegation design, a class loader delegates class loading to its parent before attempting to load a class itself. If the parent class loader cannot load a class, the class loader attempts to load the class itself. In effect, a class loader is responsible for loading only the classes not available to the parent. Classes loaded by a class loader higher in the hierarchy cannot refer to classes available lower in the hierarchy.
note: Related documentation for GF3.1 is here and here
However you may influence the behavior through glassfish specific descriptor with
<class-loader delegate="true/false"/>
You can find more about it following the first link
Related
Here I am getting below error while connect using HttpPost,
Caused by: java.lang.LinkageError: loader constraint violation: loader
(instance of org/jboss/osgi/framework/internal/HostBundleClassLoader)
previously initiated loading for a different type with name
"org/apache/http/client/methods/HttpPost"
And I am using OSGI bundle so I have added all required dependent files.
So can anyone help me to resolve it?
The Java language is based on a single namespace. That is, the language is built around the concept that a class name is used only once. Classloaders were designed to load code over the internet but accidentally allowed the same class name to be used by 2 class loaders.
In OSGi, each bundle has a class loader that directly loads the classes from its own bundle but uses the class loader of other bundles for any imported classes.
In such a mesh of class loaders, you get the situation that you can load a class C from a Bundle that references a class X and a class Y loaded from other class loaders. Since they have different names that is ok. However, X could refer to class Z and Y could refer to Z, and they could come from different loaders. The original class C from Bundle A, therefore, can see Z from two different class loaders. And is a Linkage Error.
This mesh of classloaders works very well when all bundles are correct, you should never get this kind of errors when you do not hack your bundles. These errors are inevitably caused by complex setups that do not follow the OSGi rules and maintain the Bundle's manifest by hand.
In this case, the class name that can be seen multiple times is org.apache.http.client.methods.HttpPost. So you have a setup where there are multiple bundles exporting this class, which is the first place to look. Since you could start the bundle, the metadata is wrong. OSGi has special metadata that makes this error detected before you start the bundle, the so-called uses constraints.
On Apache Felix, you get an extensive analysis of the problem. If you could run your code on Apache Felix, that would be the easiest route. Looking at your error, you seem to be running on JBoss. They always have played a bit loose with the OSGi rules to make it easier to run enterprise software. Software that rarely does the work to provide OSGi metadata and is well known for its class loader hacks. (A lot of people are only after the Java Module System starting to understand what OSGi was doing and needed.)
I am trying to nest a #RestController jar dependency in side #controller parent project. Both are maven build and spring boot projects. But at once only one of the controller works. For instance if i put package scan in the parent's code i.e #controller's jar file all the features of view resolver is lost but #restcontroller works. By removing the package scan form parent ,#controller works. So can any one help me to get both of the controller types working under same jar??
Apologies guys. Found the issue , this was acutally related to two configuration files one in the child and one in the parent jar both having #EnableWebMvc due to which the package scan was making a particular boot project up and other one not to respond.
Now i shifted the configuration to the the parent ,provided resource locations and / mapping to the index.html file . Every thing runs as expected (Only the child jar no-loger can be run independently as used to earlier)
If I have a dependency of scope 'test' that is not an OSGi bundle, should I expect pax-exam to simply incorporate it in the probe bundle, or do I need to explicitly wrap it?
I have a case where neither approach is working., and I'm trying to diagnose the problem.
The probe bundle only includes the classes from the class path component containing the test class (usually just what's in src/test/java of your project).
You can customize the probe, or simply provision your test dependencies as separate bundle. The probe imports all packages dynamically.
My ear application which runs on JBoss AS 7.1.0.Final consists of two jars:
lib/one.jar
lib/two.jar
Both jars are CDI bean archives.
The two.jar depends on one.jar.
The class beeing decorated is in one.jar.
The decorator class is in two.jar
If the decorators are declared in beans.xml of two.jar, they are not enabled.
Does this work as expected?
Since the one.jar is developed independent of the two.jar and has no dependency to the two.jar, I expect the declaration (enabling) of the decorators is in the archive where the decorator classes are stored.
How is it possible to enable a decorator class without to change the archive with classes beeing decorated?
According to the spec, yes this is expected behaviour. CDI 1.1 is hoping to make this easier or at least clear it up a little. For any interceptor, decorator, or alternative you want to use, it must be enabled (beans.xml) in the archive you wish to use it.
In the simplest of Flex Projects, create an MXML Flex Module and then load it using the ModuleManager. No problem. Create an ActionScript class that extends Module and then configure your project to compile that into a Module. Load this new module instead. The project compiles, but crashes when running with the following error:
"Error: Could not find compiled resource bundle 'containers' for locale 'en_US'."
I believe the compiler is failing to compile the required class definitions into ActionScript only module, while it succeeds for the MXML module. I can see that my skeleton MXML module is slightly larger than my ActionScript module (66KB vs. 45KB).
How can I resolve this problem (if that is indeed the issue)?
A good approach in these sort of situations is to use -keep-generated-actionscript for two projects, one with the mxml approach, and one with the actionscript approach. You can then compare the code to see what might be missing from one project, but included in another.
Have you tried adding an explicit reference to [ResourceBundle("containers")] to your ActionScript project class? The mxmlc is different to the compc compiler in behaviour for many valid reasons.
I was having this same problem when compiling a library swc. I was able to fix it by adding the following section to the projects projectName-config.xml
<include-libraries append="true">
<library>${flexlib}/locale/{locale}/framework_rb.swc</library>
</include-libraries>
This forces the compiler to include the framework resource bundle for the specified locale.
for me the issue was finding out which project - in my case a library - and which class in this library caused this behavior (I needed to realize my last changes - no info from flashbuilder). Then applying the following attribute to the class:
[ResourceBundle("containers")]
public class IpChecker {
...
That did the trick.