Using Third Party Libraries

Embedding JARs

JARs can be included in a plugin by storing them in a lib directory at the root of your plugin directory.

Using the JARs

Plugins have a special class loader that automatically loads JARs embedded in the lib directory.

Tip

JARs in a plugin cannot be accessed from outside the plugin : you cannot access the JARs embedded in a plugin "bar" with a code that resides in the "foo" plugin.

You can access static methods of java classes using the com.noheto.plugins.IPlugin invoke method.

Because of this limitation, if you need to use a third party JAR, you will add the third party JAR in the lib directory, create your own jar containing classes that will define proxy static methods for accessing the third party JAR.

For instance, you cannot access directly a constructor using the IPlugin#invoke method. You would create a factory class for creating instances of the requested class.

Limits of reflection

Because the invoke method uses reflection to find out which method it should invoke on a class, you might be blocked quickly if the requested method is waiting for a Map as you cannot have an instance of a Map exactly : it would be an HashMap or TreeMap or other but could not be a Map as Map is an interface.

Groovy to the rescue

Fortunatly, Wedia provides a work around method by using groovy : the noheto:script is defined to let you insert groovy script either by writing the Groovy script directly in the body tag or by specifying the path to a Groovy script (have a look to the taglib documentation for more details).

<%@page pageEncoding="ISO-8859-15" %> <%@taglib prefix="noheto" uri="/WEB-INF/noheto.tld" %> <%@taglib prefix="c" uri="/WEB-INF/c.tld" %> <noheto:skipPage test="${not pageContext.request.included}"/> <noheto:script> def myMap = [:] myMap["foo"] = "bar" def res = plugin.invoke("my.package.MyClass", "mapBasedStaticMethod", myMap) </noheto:script>