[xwiki-users] Registering components
Having been put off writing Java components a number of times I've decided to really tackle the problem head on. I would greatly appreciate any help in this. I've been following the advice in http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents and I have compiled a Jar identical to the Hello World example except that the class and method names differ, hopefully consistently. I've placed the jar in XE_WAR_HOME/WEB-INF/lib and written a page, which consists only of {{velocity}} $services.mycomponent.greet() {{/velocity}} The output when viewed is simple "$services.alertdb.greet()", so nothing seems to have happened. However, if I restart Tomcat (and then wait a minute or so for XWiki to restart) the output is "Hello", as desired. So is a restart of Tomcat always required? This wasn't mentioned in the guide. And since extensions can be added via the extension manager without a restart, is there a sneaky trick to doing the same with my own components. Also, is a restart necessary when I update the Jar, either with fixed methods or modified interface?
What you have in XE_WAR_HOME/WEB-INF/lib is loaded by Tomcat at startup, there is not much XWiki can do about it. But you can install your jar as an extension using Extension Manager as long as it's on some supported repository (which mean a Maven repository or XWiki repository, see http://extensions.xwiki.org/xwiki/bin/view/Extension/Repository+Application for this last one) and you indicate your repository in xwiki.properties. On Thu, Nov 27, 2014 at 5:20 AM, Bryn Jeffries <[email protected]> wrote:
Having been put off writing Java components a number of times I've decided to really tackle the problem head on. I would greatly appreciate any help in this.
I've been following the advice in http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents and I have compiled a Jar identical to the Hello World example except that the class and method names differ, hopefully consistently. I've placed the jar in XE_WAR_HOME/WEB-INF/lib and written a page, which consists only of {{velocity}} $services.mycomponent.greet() {{/velocity}}
The output when viewed is simple "$services.alertdb.greet()", so nothing seems to have happened. However, if I restart Tomcat (and then wait a minute or so for XWiki to restart) the output is "Hello", as desired.
So is a restart of Tomcat always required? This wasn't mentioned in the guide. And since extensions can be added via the extension manager without a restart, is there a sneaky trick to doing the same with my own components.
Also, is a restart necessary when I update the Jar, either with fixed methods or modified interface? _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
On Thu, Nov 27, 2014 at 8:36 AM, Thomas Mortagne <[email protected]> wrote:
What you have in XE_WAR_HOME/WEB-INF/lib is loaded by Tomcat at startup, there is not much XWiki can do about it.
But you can install your jar as an extension using Extension Manager as long as it's on some supported repository (which mean a Maven repository or XWiki repository, see http://extensions.xwiki.org/xwiki/bin/view/Extension/Repository+Application for this last one) and you indicate your repository in xwiki.properties.
Note that Extension Manager is not the best fit right now to test snapshot jars since it does not have the required special handling of SNAPSHOT needed to update to a new version of the same SNAPSHOT version.
On Thu, Nov 27, 2014 at 5:20 AM, Bryn Jeffries <[email protected]> wrote:
Having been put off writing Java components a number of times I've decided to really tackle the problem head on. I would greatly appreciate any help in this.
I've been following the advice in http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents and I have compiled a Jar identical to the Hello World example except that the class and method names differ, hopefully consistently. I've placed the jar in XE_WAR_HOME/WEB-INF/lib and written a page, which consists only of {{velocity}} $services.mycomponent.greet() {{/velocity}}
The output when viewed is simple "$services.alertdb.greet()", so nothing seems to have happened. However, if I restart Tomcat (and then wait a minute or so for XWiki to restart) the output is "Hello", as desired.
So is a restart of Tomcat always required? This wasn't mentioned in the guide. And since extensions can be added via the extension manager without a restart, is there a sneaky trick to doing the same with my own components.
Also, is a restart necessary when I update the Jar, either with fixed methods or modified interface? _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
-- Thomas Mortagne
I wrote:
So is a restart of Tomcat always required? This wasn't mentioned in the guide. And since extensions can be added via the extension manager without a restart, is there a sneaky trick to doing the same with my own components.
Thomas Mortagne wrote:
What you have in XE_WAR_HOME/WEB-INF/lib is loaded by Tomcat at startup, there is not much XWiki can do about it.
It also seems that restarting Tomcat isn't always sufficient to update a component. I've updated the jar file a couple of times and seen the same behaviour after the restart. I notice that in the Tomcat docs there is a reloadable attribute for the org.apache.catalina.Loader interface http://tomcat.apache.org/tomcat-7.0-doc/config/loader.html "Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. You can use the Manager web application, however, to trigger reloads of deployed applications on demand." Doesn't that mean that the corresponding XWiki class could support reloading as a configurable option?
On Sun, Nov 30, 2014 at 8:11 PM, Bryn Jeffries <[email protected]> wrote:
I wrote:
So is a restart of Tomcat always required? This wasn't mentioned in the guide. And since extensions can be added via the extension manager without a restart, is there a sneaky trick to doing the same with my own components.
Thomas Mortagne wrote:
What you have in XE_WAR_HOME/WEB-INF/lib is loaded by Tomcat at startup, there is not much XWiki can do about it.
It also seems that restarting Tomcat isn't always sufficient to update a component. I've updated the jar file a couple of times and seen the same behaviour after the restart.
I notice that in the Tomcat docs there is a reloadable attribute for the org.apache.catalina.Loader interface http://tomcat.apache.org/tomcat-7.0-doc/config/loader.html "Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. You can use the Manager web application, however, to trigger reloads of deployed applications on demand."
Doesn't that mean that the corresponding XWiki class could support reloading as a configurable option?
You don't win much time by relaoding Tomcat instead of restarting it, the purely Tomcat side is quick compared to XWiki init. Usually the best is to test everything you can using junit (plus and you always sleep better with a good code coverage :)) and only test a few complex scenario hard to mock with the complete stack.
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Thomas Mortagne wrote:
I notice that in the Tomcat docs there is a reloadable attribute for the org.apache.catalina.Loader interface [...] Doesn't that mean that the corresponding XWiki class could support reloading as a configurable option?
You don't win much time by relaoding Tomcat instead of restarting it, the purely Tomcat side is quick compared to XWiki init.
Usually the best is to test everything you can using junit (plus and you always sleep better with a good code coverage :)) and only test a few complex scenario hard to mock with the complete stack.
Yes, I'm coming around to thinking that's the simplest approach. I tried setting the Context to reloadable in xwiki.xml and adding my component as a watched resource: <Context path="/xwiki" docBase="/usr/lib/xwiki" privileged="true" allowLinking="true" crossContext="true" reloadable="true"> <!-- make symlinks work in Tomcat --> <Resources className="org.apache.naming.resources.FileDirContext" allowLinking="true" /> <!-- allow hot reload of my component --> <WatchedResource>/usr/lib/xwiki/WEB-INF/lib/mycomponent.jar</WatchedResource> </Context> This seemed to trigger a reload of the whole of XWiki, which wasn't pretty, though it did do the job. Alas it generated a lot of errors in the log in the process, of the form: SEVERE: The web application [/xwiki] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. SEVERE: The web application [/xwiki] created a ThreadLocal with key of type [com.xpn.xwiki.store.migration.AbstractDataMigrationManager.ThreadLock] (value [com.xpn.xwiki.store.migration.AbstractDataMigrationManager$ThreadLock@334be165]) and a value of type [java.lang.Integer] (value [0]) but failed to remove it when the web application was stopped. And lots more of the above. So I won't be doing this... Incidentally, I think I was wrong about old code persisting after a restart of Tomcat - I reckon I just missed a step in my process.
participants (2)
-
Bryn Jeffries -
Thomas Mortagne