Class loading issue for plugin
Oxygen general issues.
-
- Posts: 10
- Joined: Thu Aug 09, 2012 3:27 pm
Class loading issue for plugin
I am developing a custom plugin and am running into issues with class loading it looks like? I placed the following into my plugin.xml file:
These are the issues:
I am using a ScriptEngineFactory class from a script-api.jar library to use for beanshell scripting. This is the following error that I get:
From code:
Trying to place saxon9 jars on the runtime path is resulting in the following warnings:
Code: Select all
classLoaderType="preferReferencedResources"
I am using a ScriptEngineFactory class from a script-api.jar library to use for beanshell scripting. This is the following error that I get:
Code: Select all
"Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.sun.script.javascript.RhinoScriptEngineFactory cannot be cast to javax.script.ScriptEngineFactory"
Code: Select all
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
private ScriptEngineManager mgr = new ScriptEngineManager();;
private ScriptEngine bshEngine = mgr.getEngineByName("beanshell");
Trying to place saxon9 jars on the runtime path is resulting in the following warnings:
Code: Select all
Warning: external object model net.sf.saxon.dom.DOMEnvelope has been loaded, but is not an instance of net.sf.saxon.om.ExternalObjectModel
Warning: external object model net.sf.saxon.dom.DOMObjectModel has been loaded, but is not an instance of net.sf.saxon.om.ExternalObjectModel
-
- Posts: 9446
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Class loading issue for plugin
Hi,
I need to know the exact libraries you are referencing.
Maybe you can paste the entire plugin.xml content in the reply.
Oxygen creates a separate class loader for each loaded plugin.
If you set preferReferencedResources then your referenced JARs will be preferred, for example your Saxon 9 jars will be preferred even if Oxygen comes with its own Saxon 9 jars.
But:
Your plugin's code is usually called by Oxygen from a user interface thread which has as a class loader Oxygen's main class loader.
Some libraries use the context class loader set on the thread to load certain resources.
So when calling code which works with these libraries you should do the following:
Regards,
Radu
I need to know the exact libraries you are referencing.
Maybe you can paste the entire plugin.xml content in the reply.
Oxygen creates a separate class loader for each loaded plugin.
If you set preferReferencedResources then your referenced JARs will be preferred, for example your Saxon 9 jars will be preferred even if Oxygen comes with its own Saxon 9 jars.
But:
Your plugin's code is usually called by Oxygen from a user interface thread which has as a class loader Oxygen's main class loader.
Some libraries use the context class loader set on the thread to load certain resources.
So when calling code which works with these libraries you should do the following:
Code: Select all
ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(CustomWorkspaceAccessPluginExtension.class.getClassLoader());
//AND YOUR CODE SHOULD GO HERE
} finally {
Thread.currentThread().setContextClassLoader(currentCL);
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service