#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0

    Loading Java JAR's in CF10


    I'm trying to load the Docx4j JAR file. But I keep getting a class not found... even though I specified where the JAR is located in the Application.cfc:

    Code:
    <cfcomponent output="false">
    
    	<cfset this.javaSettings =
    		{LoadPaths = ["/myJava/lib"], loadColdFusionClassPath = true, reloadOnChange= true, 
    		watchInterval = 100, watchExtensions = "jar,class,xml"} />
    
    </cfcomponent>
    EDIT:

    http://www.docx4java.org/trac/docx4j

    When dealing with JAR's I am guessing we use dot notation to transverse and find the class that we need?

    This doesn't work:

    Code:
    <cfset docObj = createObject("java","org.docx4j.openpackaging.packages.WordprocessingMLPackage") />
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    Yes, that's the right syntax. You'll need to be sure the method exists, that you're passing any required parameters into the constructor (if there are any constructor args), and that they are of the proper Java type.

    I actually haven't tried the new class loader in CF 10 though.
  4. #3
  5. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    You might try specifying an absolute path to the library folder to make sure it's pointing where you think it should be.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Ah, I got it to work now. These objects require the init() constructor to be supplied to them.

    Code:
    <cfset docObj = createObject("java","org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart").init() />
    <cfset docPackageObj = createObject("java","org.docx4j.openpackaging.packages.WordprocessingMLPackage").init() />
    This is actually, very good news since it is telling me that CF10 can actually work around class loading issues.
  8. #5
  9. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    This has actually been available for a while as an open-source add on called JavaLoader. Adobe just realized it was very useful and incorporated it with some modifications.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by kiteless
    This has actually been available for a while as an open-source add on called JavaLoader. Adobe just realized it was very useful and incorporated it with some modifications.
    Do you know what modifications were made or where to find the official documentation on this feature? I was curious how it differs from the javaLoader, but my google must be broken because I am coming up with zip... ;-)
  12. #7
  13. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    I'm actually not sure. I don't think it was anything major though, just tighter integration with CF (obviously, heh).
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Yeah, Mark Mandel must be so proud

    Finally found some documentation on it here:
    http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSe61e35da8d318518-106e125d1353e804331-7ffe.html
  16. #9
  17. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    I know Mark pretty well and he's actually not super thrilled about having all that work appropriated heh. Ah, the perils of open source.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by kiteless
    I know Mark pretty well and he's actually not super thrilled about having all that work appropriated heh. Ah, the perils of open source.
    Having used every one of the javaLoader's incarnations, I do not blame him. It is a fantastic piece of work. (If you could hear my tone, the "proud" comment was injected with a wealth of sarcasm

IMN logo majestic logo threadwatch logo seochat tools logo