Index: src/main/java/com/xpn/xwiki/api/XWiki.java
===================================================================
--- src/main/java/com/xpn/xwiki/api/XWiki.java	(revision 4385)
+++ src/main/java/com/xpn/xwiki/api/XWiki.java	(working copy)
@@ -2403,6 +2403,22 @@
      * @return An object instanciating this class
      * @throws XWikiException
      */
+    public Object parseGroovyFromPage(String fullname, String jarWikiPage) throws XWikiException
+    {
+        XWikiDocument doc = xwiki.getDocument(fullname, getXWikiContext());
+        if (xwiki.getRightService().hasProgrammingRights(doc, getXWikiContext()))
+            return xwiki.parseGroovyFromString(doc.getContent(), jarWikiPage, getXWikiContext());
+        return "groovy_missingrights";
+    }
+
+    /**
+     * Priviledged API to retrieve an object instanciated from groovy code in a String Groovy
+     * scripts compilation is cached
+     *
+     * @param fullname // script containing a Groovy class definition (public class MyClass { ... })
+     * @return An object instanciating this class
+     * @throws XWikiException
+     */
     public Object parseGroovyFromPage(String fullname) throws XWikiException
     {
         XWikiDocument doc = xwiki.getDocument(fullname, getXWikiContext());
Index: src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java
===================================================================
--- src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java	(revision 4385)
+++ src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java	(working copy)
@@ -316,6 +316,7 @@
     public Object parseGroovyFromString(String script, XWikiContext context) throws XWikiException
     {
         prepareCache(context);
+        ClassLoader parentClassLoader = (ClassLoader) context.get("parentclassloader");
         try {
             CachedGroovyClass cgc;
             Class gc;
@@ -325,7 +326,7 @@
             }
             catch (XWikiCacheNeedsRefreshException e) {
                 classCache.cancelUpdate(script);
-                GroovyClassLoader gcl = new GroovyClassLoader();
+                GroovyClassLoader gcl = (parentClassLoader==null) ? new GroovyClassLoader() : new GroovyClassLoader(parentClassLoader);
                 gc = gcl.parseClass(script);
                 cgc = new CachedGroovyClass(gc);
                 classCache.putInCache(script, cgc);
Index: src/main/java/com/xpn/xwiki/render/groovy/XWikiPageClassLoader.java
===================================================================
--- src/main/java/com/xpn/xwiki/render/groovy/XWikiPageClassLoader.java	(revision 0)
+++ src/main/java/com/xpn/xwiki/render/groovy/XWikiPageClassLoader.java	(revision 0)
@@ -0,0 +1,76 @@
+package com.xpn.xwiki.render.groovy;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.doc.XWikiAttachment;
+
+import java.net.URLClassLoader;
+import java.net.URL;
+import java.net.URLStreamHandlerFactory;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Copyright 2006,XpertNet SARL,and individual contributors as indicated
+ * by the contributors.txt.
+ * <p/>
+ * This is free software;you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation;either version2.1of
+ * the License,or(at your option)any later version.
+ * <p/>
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * Lesser General Public License for more details.
+ * <p/>
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software;if not,write to the Free
+ * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
+ * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
+ *
+ * @author ldubost
+ */
+
+public class XWikiPageClassLoader extends URLClassLoader {
+
+    public XWikiPageClassLoader(URL[] urls, ClassLoader parent) {
+        super(urls, parent);
+    }
+
+    public XWikiPageClassLoader(URL[] urls) {
+        super(urls);
+    }
+
+    public XWikiPageClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
+        super(urls, parent, factory);
+    }
+
+    public XWikiPageClassLoader(String jarWikiPage, XWikiContext context) throws XWikiException {
+        this(jarWikiPage, Thread.currentThread().getContextClassLoader(), context);
+    }
+
+    public XWikiPageClassLoader(String jarWikiPage, ClassLoader parent, XWikiContext context) throws XWikiException {
+        super(new URL[0], parent);
+        XWikiDocument doc = context.getWiki().getDocument(jarWikiPage, context);
+        List urlList = new ArrayList();
+        if (!doc.isNew()) {
+            List attachList = doc.getAttachmentList();
+            for (int i=0;i<attachList.size();i++) {
+                XWikiAttachment attach = (XWikiAttachment) attachList.get(i);
+                String filename = attach.getFilename();
+                if (filename.endsWith(".jar")) {
+                    try{
+                        urlList.add(new URL(doc.getExternalAttachmentURL(filename, "download", context)));
+                    } catch (Exception e) {};
+                }
+            }
+        }
+        if (urlList.size()>0) {
+            for (int i=0;i<urlList.size();i++) {
+                addURL((URL) urlList.get(i));
+            }
+        }
+    }
+}
Index: src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- src/main/java/com/xpn/xwiki/XWiki.java	(revision 4391)
+++ src/main/java/com/xpn/xwiki/XWiki.java	(working copy)
@@ -42,6 +42,7 @@
 import com.xpn.xwiki.render.XWikiRenderingEngine;
 import com.xpn.xwiki.render.XWikiVelocityRenderer;
 import com.xpn.xwiki.render.groovy.XWikiGroovyRenderer;
+import com.xpn.xwiki.render.groovy.XWikiPageClassLoader;
 import com.xpn.xwiki.stats.api.XWikiStatsService;
 import com.xpn.xwiki.stats.impl.SearchEngineRule;
 import com.xpn.xwiki.stats.impl.XWikiStatsServiceImpl;
@@ -5034,21 +5035,49 @@
     }
 
     public Object parseGroovyFromString(String script, XWikiContext context)
-        throws XWikiException
+            throws XWikiException
     {
-        if (getRenderingEngine().getRenderer("groovy") != null)
+        if (getRenderingEngine().getRenderer("groovy") == null)
+            return null;
+        else
             return ((XWikiGroovyRenderer) getRenderingEngine().getRenderer("groovy"))
-                .parseGroovyFromString(script, context);
-        return null;
+                    .parseGroovyFromString(script, context);
     }
 
+    public Object parseGroovyFromString(String script, String jarWikiPage, XWikiContext context)
+            throws XWikiException
+    {
+        if (getRenderingEngine().getRenderer("groovy") == null)
+            return null;
+
+
+        XWikiPageClassLoader pcl = new XWikiPageClassLoader(jarWikiPage, context);
+        Object prevParentClassLoader = context.get("parentclassloader");
+        try {
+            context.put("parentclassloader", pcl);
+            return parseGroovyFromString(script, context);
+        } finally {
+            if (prevParentClassLoader==null)
+                context.remove("parentclassloader");
+            else
+                context.put("parentclassloader", prevParentClassLoader);
+        }
+    }
+
     public Object parseGroovyFromPage(String fullname, XWikiContext context)
-        throws XWikiException
+            throws XWikiException
     {
         return parseGroovyFromString(context.getWiki().getDocument(fullname, context)
-            .getContent(), context);
+                .getContent(), context);
     }
 
+    public Object parseGroovyFromPage(String fullName, String jarWikiPage, XWikiContext context)
+            throws XWikiException
+    {
+        return parseGroovyFromString(context.getWiki().getDocument(fullName, context)
+                .getContent(), context);
+    }
+
     public String getMacroList(XWikiContext context)
     {
         String macrosmapping = "";
