Hot questions for Using GlassFish in classloader

Question:

I need to load the manifest of an application I am deploying on Glassfish as an EAR.

All the info I've found on internet is regarding reading manifests of jars or wars. I've tried to apply the snippets of code I've found to my problem but I've not made it. What i get is that I can have any manifest, either from the jars that my EAR contains, or even from the jars in the Glassfish domain lib folder. Not the one of the EAR.

Structure of the EAR: At root level there are some jars, one of which contains the class with the code that intends to load the EAR manifest.

ClassLoader cl = getClass().getClassLoader();
resources = cl.getResources("META-INF/MANIFEST.MF");

I've tried the getResourceAsStream method, but since that failed to give me the manifest I wanted, I tried the getResources method to see all the manifests it can give me and iterate them, taking a look at the path where they are. And none of them is the EAR manifest. I get the manifests of all the jars in my EAR, and all the lib jars in the Glassfish domain.

I've also tried casting the getClassLoader as URLClassLoader and EarClassLoader, as suggested in other StackOverFlow similar questions, seeing no difference in results.

This EAR is generated from a project in MyEclipse which has only the EAR facet. That project contains no code and just references the other projects which end up making the jars inside it.


Answer:

The MANIFEST.MF for the .ear is not on the classpath, you would have to actually open the .ear as a regular zip file and read it that way.

Question:

I hava a web application that should run on glassfish.

The application uses jna version 4.1.0 and the jna-4.1.0.jar is packed with the application inside its lib folder.

Howerver, as far as I can tell the glassfish itself uses version 3.1 of the jna library and it is packed inside ibpam4j-repackaged.jar on the following path:

('C:/Program Files/glassfish-4.1.1/glassfish/modules').

As a result - the application is not running, and it throws

java.lang.NoSuchMethodError: com.sun.jna.Pointer.getWideString(J)Ljava/lang/String;

cause the wrong version of the library is being used.

Any Ideas how to overcome this issue?

Thanks.

(By the way it is not my application per se - I am just trying to run a waffle example on glassfish)


Answer:

It turns out that setting <class-loader delegate="false"/> inside the glassfish-web.xml does the trick.

Everything works now.

Question:

I have Guava class loading issues and can resolve all issues by adding a glassfish-web.xml as stated in the official documentation.

However I don't want to add a not backward compatible glassfish-web.xml (deployment on Glassfish 3.1.2.2 is not working) and activate this class loading within Payara 162 itself as stated in the official documentation and the blog article to release 162.

I didn't find an exact specification on how to set this system property and as no way is working currently I simply tried all individually.

  1. jvm-option
    • asadmin create-jvm-options --target server-config -Dfish.payara.classloading.delegate=false
  2. system property
    • asadmin create-system-properties --target domain fish.payara.classloading.delegate=false
    • asadmin create-system-properties --target server fish.payara.classloading.delegate=false
    • asadmin create-system-properties --target server-config fish.payara.classloading.delegate=false
    • all three system property targets together

None of this ways worked.


Answer:

It's a feature, not a bug :(

As mentioned by the developer it is intended for WARs to not obey the global system setting. The only way to achieve this for WARs is to add the configuration in the glassfish-web.xml.

https://github.com/payara/Payara/issues/1249