Page 1 of 1

Reference to files in webapp from java sfs extensions

Posted: 06 Aug 2012, 09:53
by GrinReaper
I'm referencing a class included in the web service (deployed as a war via jetty on SFS) in a java extension. The extension is unable to locate the class giving the following error:

Code: Select all

jvm 1    | Exception in thread "SmartFoxServer" java.lang.NoClassDefFoundError: com/skilrock/rummy/service/GameMgmtService
jvm 1    | 	at java.lang.Class.getDeclaredConstructors0(Native Method)
jvm 1    | 	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
jvm 1    | 	at java.lang.Class.getConstructor0(Class.java:2699)
jvm 1    | 	at java.lang.Class.newInstance0(Class.java:326)
jvm 1    | 	at java.lang.Class.newInstance(Class.java:308)
jvm 1    | 	at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.loadExtension(ExtensionHandler.java:117)
jvm 1    | 	at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.createExtension(ExtensionHandler.java:207)
jvm 1    | 	at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.createExtension(ExtensionHandler.java:189)
jvm 1    | 	at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.parse_Extensions(ExtensionHandler.java:649)
jvm 1    | 	at it.gotoandplay.smartfoxserver.SmartFoxServer.setupZone(SmartFoxServer.java:2085)
jvm 1    | 	at it.gotoandplay.smartfoxserver.lib.ConfigReader.parse_Zones(ConfigReader.java:806)
jvm 1    | 	at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigReader.java:174)
jvm 1    | 	at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFoxServer.java:339)
jvm 1    | 	at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:607)
jvm 1    | Caused by: java.lang.ClassNotFoundException: com.skilrock.rummy.service.GameMgmtService
jvm 1    | 	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
jvm 1    | 	at java.security.AccessController.doPrivileged(Native Method)
jvm 1    | 	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
jvm 1    | 	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
jvm 1    | 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
jvm 1    | 	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
jvm 1    | 	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
jvm 1    | 	... 14 more
Is it possible to do this or am I doing something wrong here?

Thanks :)

Re: Reference to files in webapp from java sfs extensions

Posted: 07 Aug 2012, 11:55
by Lapo
They are different classloaders (Jetty and SmartFoxServer) so it won't work. SFS needs the libraries in its lib/ folder in order to be seen at the classpath level.
Thanks

Re: Reference to files in webapp from java sfs extensions

Posted: 07 Aug 2012, 12:02
by GrinReaper
So, if a user enters the parameters of a room via a jsp running on the web service, there is no way to directly access those from the extension to create a room with those parameters? Or, is there some workaround (without involving the use of a database to store those parameters).

Re: Reference to files in webapp from java sfs extensions

Posted: 28 Aug 2012, 07:52
by Lapo
There is an easier way which is calling the API directly from the servlet.
You collect the parameters in the servlet, create the RoomSettings object and finally call the SFSAPI.createRoom(...) method.

If you don't want to duplicate code in your Extension and in the servlet you can deploy a Class that takes care of the Room creation under the extensions/__lib__/ folder. This way it can be seen both by your Extensions and the servlet, and you avoid the code duplication.

Cheers