Page 1 of 1
Trouble loading extension libraries
Posted: 05 Apr 2016, 19:08
by simpleSimon
So, I'm writing mutliple extensions. I need to share the Adobe flex library (flex-messaging-core-4.7.0.jar). So I put it in the extensions/__lib__ directory. It didn't load even if with a server restart. So I also put it in one of my extensions directories, and it didn't load when the extension was loaded even with a server restart. So I even tried putting it in the SFS2X/lib directory. It didn't load.
What am I missing? Is there a dependency file I need to configure somewhere?
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 07:30
by Lapo
Hi,
too many libraries

You just need to put them in one place.
So, if you just need the dependency for your Extension put it in the same folder, side by side with your Extension jar.
If you need to share the library across multiple Extensions then deploy it to extension/__lib__/
Now, when you say it did not load what do you mean. What is exactly the error that you're getting?
Thanks
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 13:52
by simpleSimon
Thanks, Lapo
When I attempt to use a class from the jar library (specifically flex.messaging.io.amf.Amf3Output), I get a no class found error. For the purposes of simplicity of testing this I have put the flex jar in the same folder as one of my extensions and tried to use it from there:
java.lang.NoClassDefFoundError: flex/messaging/LocalizedException
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.access$100(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.access$100(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
com.ganz.api.DTO.wind(DTO.java:66)
com.ganz.sfsextension.NotificationExtension$RequestHandler.handleClientRequest(NotificationExtension.java:523)
com.ganz.sfsextension.NotificationExtension$ListenHandler.handleClientRequest(NotificationExtension.java:528)
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 14:00
by simpleSimon
Also, in case it helps:
$ pwd
/root/SmartFoxServer_2X/SFS2X/extensions/notificationExtension
$ ls -l
total 884
-rw-r--r-- 1 root root 184 Mar 29 16:15 APIServer.xml
-rw-r--r-- 1 root root 110 Mar 29 16:34 config.properties
-rw-r--r-- 1 root root 703233 Apr 5 14:13 flex-messaging-core-4.7.0.jar
-rw-r--r-- 1 root root 96452 Apr 5 14:13 NotificationExtension.jar
$ unzip -l flex-messaging-core-4.7.0.jar | grep Amf3Output
21860 03-01-2015 21:43 flex/messaging/io/amf/Amf3Output.class
$
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 15:03
by Lapo
Please note that the problem is not with the class you're trying to use --> flex.messaging.io.amf.Amf3Output, but with an exception class:
java.lang.NoClassDefFoundError: flex/messaging/LocalizedException
I have downloaded the flex-messaging-core-4.7.0.jar file and the class the server is complaining about is infact not contained in the jar. Hence the problem.
It looks like the jar you're trying to use is dependent on other libraries.
Cheers
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 17:18
by simpleSimon
Good catch Lapo. Thanks!
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 19:46
by simpleSimon
Unfortunately adding the missing jar containing the offending class did not solve the problem.
$ pwd
/root/SmartFoxServer_2X/SFS2X/extensions/notificationExtension
$ ls -l
total 908
-rw-r--r-- 1 root root 184 Mar 29 16:15 APIServer.xml
-rw-r--r-- 1 root root 110 Mar 29 16:34 config.properties
-rw-r--r-- 1 root root 111698 Apr 6 11:25 flex-messaging-common-4.7.2.jar
-rw-r--r-- 1 root root 705068 Apr 6 11:25 flex-messaging-core-4.7.2.jar
-rw-r--r-- 1 root root 97112 Apr 6 15:35 NotificationExtension.jar
$ unzip -l flex-messaging-common-4.7.2.jar | grep LocalizedException
4562 11-05-2015 22:02 flex/messaging/LocalizedException.class
$
From the log, same error
java.lang.NoClassDefFoundError: flex/messaging/LocalizedException
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
.
.
.
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 20:17
by simpleSimon
Truly bizarre. I put this straight in line in my code:
flex.messaging.io.SerializationContext context = flex.messaging.io.SerializationContext.getSerializationContext(); // Get Serialization Context
flex.messaging.LocalizedException f = new flex.messaging.LocalizedException(); // Create a LocalizedException class instance
f.setDetails("**** This is a test"); // Set its string details
String info = f.getDetails(); // Get its string details
trace(info); // Send to log
flex.messaging.io.amf.Amf3Output output = new flex.messaging.io.amf.Amf3Output(context); // create an Amf3Output object
And here's the log. I use the class, and yet flex gets a NoClassDefFoundError
06 Apr 2016 | 16:04:39,002 | INFO | SFSWorker:Ext:4 | Extensions | {notificationExtension}: NotificationExtension.handleClientRequest
06 Apr 2016 | 16:04:39,003 | INFO | SFSWorker:Ext:4 | Extensions | {notificationExtension}: NotificationExtension.listen -> wk1
06 Apr 2016 | 16:04:39,007 | INFO | SFSWorker:Ext:4 | Extensions | {notificationExtension}: **** This is a test
06 Apr 2016 | 16:04:39,009 | WARN | SFSWorker:Ext:4 | controllers.v290.ExtensionReqController | java.lang.NoClassDefFoundError: flex/messaging/LocalizedException
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.defineClass(Unknown Source)
etc...
It would seem that while the class loader is looking for Amf3Output, it finds it, but is in some other context?!?
$ java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
Re: Trouble loading extension libraries
Posted: 06 Apr 2016, 20:45
by simpleSimon
Hurray, problem solved.
A copy of the LocalizedException referring jar was in the extensions/__lib__/ directory and was the one actually being loaded, not the one in my extension directory. The jar with the actual LocalizedException definition was also in my directory and there for was in the ClassLoader instance that was a child. Therefore, the __lib__ contained jar could not access it.
Thanks for the help!