Thanks Mark.
Works a treat now. :-)
> Make sure when you create your instance of JL, you tell it to use CF as the
> parent classloader.
> Then you should have no issues.
> Mark
> On Wed, Nov 9, 2011 at 3:59 PM, Andrew <am2...@gmail.com> wrote:
>> Hi,
>> I'm trying to load a java class I wrote but ran into some "JAR Hell"
>> issues, namely:
>> org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to
>> org.apache.xml.dtm.DTMManager
>> So I did a bit of searching on this list and found some discussion
>> about the use of the ThreadContextClassLoader, as described by Mark
>> here: http://groups.google.com/group/javaloader-dev/msg/9ac22919da73324f
>> The call to my java method is from a function that is defined in a
>> CFC, however I keep running into this issue:
>> Object Instantiation Exception.
>> Class not found: coldfusion.runtime.java.JavaProxy
>> Is there anything obvious I'm doing wrong here? Here is the CFC
>> function (previously the parser was created in the CFC's init()
>> function, but I pulled it out of there in desperation - this is what
>> it looks like now):
>> <cffunction name="parseFormAnalysis" access="public"
>> returntype="any" output="false">
>> <cfargument name="meetingCode" type="string" required="true">
>> <cfset var qArticle =
>> getArticleByMeetingCodeAndType(arguments.meetingCode,2)>
>> <cfset var htmlText = qArticle.html_text>
>> <cfset var parser = "">
>> <cfset var result = "">
>> <cfscript>
>> var _Thread = createObject("java", "java.lang.Thread");//
>> using 'Thread' breaks CFB
>> var currentClassloader =
>> _Thread.currentThread().getContextClassLoader();
>> try {
>> //set the current thread's context class loader as
>> Javaloader's classloader, so
>> //dom4j doesn't die
>> var paths = ArrayNew(1);
>> paths[1] = "C:\eclipse\workspaces\cfbuilder\national-
>> website-trunk\javalib\xalan-2.7.1.jar";
>> paths[2] = "C:\eclipse\workspaces\cfbuilder\national-
>> website-trunk\javalib/natweb-java-1.0-SNAPSHOT.jar";
>> paths[3] = "C:\eclipse\workspaces\cfbuilder\national-
>> website-trunk\javalib/tagsoup-1.2.1.jar";
>> paths[4] = "C:\eclipse\workspaces\cfbuilder\national-
>> website-trunk\javalib/htmlcleaner2_1.jar";
>> paths[5] = "C:\eclipse\workspaces\cfbuilder\national-
>> website-trunk\javalib/harnesslib-3.6.5.jar";
>> paths[6] = "C:\eclipse\workspaces\cfbuilder\national-
>> website-trunk\javalib/commons-lang-2.4.jar";
>> var loader = createObject("component",
>> "javaloader.JavaLoader").init(loadPaths=paths);
>> _Thread.currentThread().setContextClassLoader(loader.getURLClassLoader());
>> parser =
>> loader.create("org.harness.natweb.parsers.FormAnalysisParser").init();
>> // the line above is the line the stack trace flags as
>> the problem
>> result = parser.parsePuntersCornerArticle(htmlText);
>> }
>> catch(Any exc) {
>> rethrow;
>> }
>> finally
>> {
>> /*
>> We have to reset the classloader, due to
>> thread pooling.
>> */
>> _Thread.currentThread().setContextClassLoader(currentClassloader);
>> }
>> </cfscript>
>> <cfreturn result>
>> </cffunction>
>> Any suggestions greatly appreciated!
>> Regards,
>> Andrew.
>> P.S. I'm using JavaLoader 1.0, and CF 9.0 in Multiserver mode under
>> JRun (NB not 9.0.1). It's pointing to
> --
> E: mark.man...@gmail.com
> T: http://www.twitter.com/neurotic
> W: www.compoundtheory.com
> cf.Objective(ANZ) + Flex - Nov 17, 18 - Melbourne Australia
> http://www.cfobjective.com.au
> 2 Devs from Down Under Podcast
> http://www.2ddu.com/