[{"data":1,"prerenderedAt":750},["ShallowReactive",2],{"post:read-java-package-version":3},{"id":4,"title":5,"body":6,"date":736,"description":737,"draft":738,"extension":739,"meta":740,"navigation":741,"path":742,"seo":743,"stem":744,"tags":745,"__hash__":749},"posts\u002Fposts\u002Fread-java-package-version.md","How to Get the Version of Any Java Package from CFML",{"type":7,"value":8,"toc":728},"minimark",[9,27,30,69,82,85,88,91,96,99,126,129,170,173,218,221,295,305,310,317,326,329,356,359,363,366,369,390,393,427,430,478,481,485,488,491,670,677,681,684,710,721,724],[10,11,12,13,20,21,26],"p",{},"The ",[14,15,19],"a",{"href":16,"rel":17},"https:\u002F\u002Fpoi.apache.org\u002F",[18],"nofollow","Apache POI library"," is an awesome tool for messing with spreadsheets. You can read spreadsheet data, get header rows, total row count, all sorts of wacky stuff. Julian Halliwell's excellent ",[14,22,25],{"href":23,"rel":24},"https:\u002F\u002Fgithub.com\u002Fcfsimplicity\u002Fspreadsheet-cfml",[18],"spreadsheet-cfml library"," uses it to great effect.",[10,28,29],{},"But when I try to use Apache POI standalone, I got an error that a method didn't exist:",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-bash shiki shiki-themes github-light github-dark","No matching Method\u002FFunction for org.apache.poi.hssf.usermodel.HSSFSheet.getTables() found\n","bash","",[38,39,40],"code",{"__ignoreMap":36},[41,42,45,49,53,56,59,62,66],"span",{"class":43,"line":44},"line",1,[41,46,48],{"class":47},"sScJk","No",[41,50,52],{"class":51},"sZZnC"," matching",[41,54,55],{"class":51}," Method\u002FFunction",[41,57,58],{"class":51}," for",[41,60,61],{"class":51}," org.apache.poi.hssf.usermodel.HSSFSheet.getTables",[41,63,65],{"class":64},"sVt8B","() ",[41,67,68],{"class":51},"found\n",[10,70,71,72],{},"It would seem that Lucee bundles an older version of Apache POI by default. (UPDATE: ",[14,73,76,77,81],{"href":74,"rel":75},"https:\u002F\u002Ftwitter.com\u002Fcfsimplicity\u002Fstatus\u002F1572226273870778376",[18],"Turns out this is only present due to the Apache Tika bundle, which ",[78,79,80],"em",{},"is"," shipped with Lucee. Thanks Julian Halliwell for that tip!",[10,83,84],{},"But what version would that be?",[10,86,87],{},"We could easily find out from the Lucee admin page, of course. Provided it is enabled.",[10,89,90],{},"But why not try to grab the POI bundle version in code? From our CFML?",[92,93,95],"h2",{"id":94},"reading-a-java-package-version-in-lucee","Reading a Java Package Version in Lucee",[10,97,98],{},"It all starts with the java class:",[31,100,104],{"className":101,"code":102,"language":103,"meta":36,"style":36},"language-js shiki shiki-themes github-light github-dark","createObject( \"java\", \"org.apache.poi.hssf.usermodel.HSSFSheet\" )\n","js",[38,105,106],{"__ignoreMap":36},[41,107,108,111,114,117,120,123],{"class":43,"line":44},[41,109,110],{"class":47},"createObject",[41,112,113],{"class":64},"( ",[41,115,116],{"class":51},"\"java\"",[41,118,119],{"class":64},", ",[41,121,122],{"class":51},"\"org.apache.poi.hssf.usermodel.HSSFSheet\"",[41,124,125],{"class":64}," )\n",[10,127,128],{},"We then grab the java classloader tied to this class:",[31,130,132],{"className":101,"code":131,"language":103,"meta":36,"style":36},"createObject( \"java\", \"org.apache.poi.hssf.usermodel.HSSFSheet\" )\n                        .getClass()\n                        .getClassLoader()\n",[38,133,134,148,160],{"__ignoreMap":36},[41,135,136,138,140,142,144,146],{"class":43,"line":44},[41,137,110],{"class":47},[41,139,113],{"class":64},[41,141,116],{"class":51},[41,143,119],{"class":64},[41,145,122],{"class":51},[41,147,125],{"class":64},[41,149,151,154,157],{"class":43,"line":150},2,[41,152,153],{"class":64},"                        .",[41,155,156],{"class":47},"getClass",[41,158,159],{"class":64},"()\n",[41,161,163,165,168],{"class":43,"line":162},3,[41,164,153],{"class":64},[41,166,167],{"class":47},"getClassLoader",[41,169,159],{"class":64},[10,171,172],{},"Once we have that, we need to grab the OSGI bundle:",[31,174,176],{"className":101,"code":175,"language":103,"meta":36,"style":36},"createObject( \"java\", \"org.apache.poi.hssf.usermodel.HSSFSheet\" )\n                        .getClass()\n                        .getClassLoader()\n                        .getBundle()\n",[38,177,178,192,200,208],{"__ignoreMap":36},[41,179,180,182,184,186,188,190],{"class":43,"line":44},[41,181,110],{"class":47},[41,183,113],{"class":64},[41,185,116],{"class":51},[41,187,119],{"class":64},[41,189,122],{"class":51},[41,191,125],{"class":64},[41,193,194,196,198],{"class":43,"line":150},[41,195,153],{"class":64},[41,197,156],{"class":47},[41,199,159],{"class":64},[41,201,202,204,206],{"class":43,"line":162},[41,203,153],{"class":64},[41,205,167],{"class":47},[41,207,159],{"class":64},[41,209,211,213,216],{"class":43,"line":210},4,[41,212,153],{"class":64},[41,214,215],{"class":47},"getBundle",[41,217,159],{"class":64},[10,219,220],{},"And finally, grab the version as a string:",[31,222,224],{"className":101,"code":223,"language":103,"meta":36,"style":36},"var version = createObject( \"java\", \"org.apache.poi.hssf.usermodel.HSSFSheet\" )\n                        .getClass()\n                        .getClassLoader()\n                        .getBundle()\n                        .getVersion()\n                        .toString()\n",[38,225,226,251,259,267,275,285],{"__ignoreMap":36},[41,227,228,232,235,238,241,243,245,247,249],{"class":43,"line":44},[41,229,231],{"class":230},"szBVR","var",[41,233,234],{"class":64}," version ",[41,236,237],{"class":230},"=",[41,239,240],{"class":47}," createObject",[41,242,113],{"class":64},[41,244,116],{"class":51},[41,246,119],{"class":64},[41,248,122],{"class":51},[41,250,125],{"class":64},[41,252,253,255,257],{"class":43,"line":150},[41,254,153],{"class":64},[41,256,156],{"class":47},[41,258,159],{"class":64},[41,260,261,263,265],{"class":43,"line":162},[41,262,153],{"class":64},[41,264,167],{"class":47},[41,266,159],{"class":64},[41,268,269,271,273],{"class":43,"line":210},[41,270,153],{"class":64},[41,272,215],{"class":47},[41,274,159],{"class":64},[41,276,278,280,283],{"class":43,"line":277},5,[41,279,153],{"class":64},[41,281,282],{"class":47},"getVersion",[41,284,159],{"class":64},[41,286,288,290,293],{"class":43,"line":287},6,[41,289,153],{"class":64},[41,291,292],{"class":47},"toString",[41,294,159],{"class":64},[10,296,297,298,304],{},"Voila! We have our package version! It seems Lucee ships with Apache POI 2.5.1, released in November 2005. ",[78,299,300],{},[301,302,303],"strong",{},"Wow",".",[306,307,309],"h3",{"id":308},"update-using-lucees-bundleinfo-method","UPDATE: Using Lucee's BundleInfo() method",[10,311,312,313,316],{},"Julian Halliwell (author of the awesome Spreadsheet CFML library) pointed out that Lucee has a ",[38,314,315],{},"bundleInfo()"," function which does the same thing:",[318,319,320],"blockquote",{},[10,321,322,323],{},"Great post! Lucee has a BundleInfo() BIF which also returns other useful info. - ",[78,324,325],{},"Julian Halliwell, @cfsimplicity",[10,327,328],{},"Using bundleInfo() would look something like this:",[31,330,332],{"className":101,"code":331,"language":103,"meta":36,"style":36},"var version = createObject( \"java\", \"org.apache.logging.log4j.LogManager\" ) ).version;\n",[38,333,334],{"__ignoreMap":36},[41,335,336,338,340,342,344,346,348,350,353],{"class":43,"line":44},[41,337,231],{"class":230},[41,339,234],{"class":64},[41,341,237],{"class":230},[41,343,240],{"class":47},[41,345,113],{"class":64},[41,347,116],{"class":51},[41,349,119],{"class":64},[41,351,352],{"class":51},"\"org.apache.logging.log4j.LogManager\"",[41,354,355],{"class":64}," ) ).version;\n",[10,357,358],{},"Honestly, this is much nicer than my implemen",[92,360,362],{"id":361},"reading-a-java-package-version-from-adobe-coldfusion","Reading a Java Package Version from Adobe ColdFusion",[10,364,365],{},"However, in Adobe CF (ACF) this fails because ACF does not architecture packages via OSGI. (Not to my knowledge, that is.) We need to find another method… and it turns out reading package details is even simpler in Adobe.",[10,367,368],{},"First, we instantiate the Java Package library:",[31,370,372],{"className":101,"code":371,"language":103,"meta":36,"style":36},"createObject( \"java\", \"java.lang.Package\" );\n",[38,373,374],{"__ignoreMap":36},[41,375,376,378,380,382,384,387],{"class":43,"line":44},[41,377,110],{"class":47},[41,379,113],{"class":64},[41,381,116],{"class":51},[41,383,119],{"class":64},[41,385,386],{"class":51},"\"java.lang.Package\"",[41,388,389],{"class":64}," );\n",[10,391,392],{},"From there, we get the Apache POI package:",[31,394,396],{"className":101,"code":395,"language":103,"meta":36,"style":36},"createObject( \"java\", \"java.lang.Package\" )\n            .getPackage( \"org.apache.poi\" );\n",[38,397,398,412],{"__ignoreMap":36},[41,399,400,402,404,406,408,410],{"class":43,"line":44},[41,401,110],{"class":47},[41,403,113],{"class":64},[41,405,116],{"class":51},[41,407,119],{"class":64},[41,409,386],{"class":51},[41,411,125],{"class":64},[41,413,414,417,420,422,425],{"class":43,"line":150},[41,415,416],{"class":64},"            .",[41,418,419],{"class":47},"getPackage",[41,421,113],{"class":64},[41,423,424],{"class":51},"\"org.apache.poi\"",[41,426,389],{"class":64},[10,428,429],{},"Once we have the POI package, we can grab the implementation version:",[31,431,433],{"className":101,"code":432,"language":103,"meta":36,"style":36},"var version = createObject( \"java\", \"java.lang.Package\" )\n                    .getPackage( \"org.apache.poi\" )\n                    .getImplementationVersion();\n",[38,434,435,455,468],{"__ignoreMap":36},[41,436,437,439,441,443,445,447,449,451,453],{"class":43,"line":44},[41,438,231],{"class":230},[41,440,234],{"class":64},[41,442,237],{"class":230},[41,444,240],{"class":47},[41,446,113],{"class":64},[41,448,116],{"class":51},[41,450,119],{"class":64},[41,452,386],{"class":51},[41,454,125],{"class":64},[41,456,457,460,462,464,466],{"class":43,"line":150},[41,458,459],{"class":64},"                    .",[41,461,419],{"class":47},[41,463,113],{"class":64},[41,465,424],{"class":51},[41,467,125],{"class":64},[41,469,470,472,475],{"class":43,"line":162},[41,471,459],{"class":64},[41,473,474],{"class":47},"getImplementationVersion",[41,476,477],{"class":64},"();\n",[10,479,480],{},"And that’s it!",[92,482,484],{"id":483},"a-cross-engine-solution","A Cross-Engine Solution",[10,486,487],{},"Sadly, neither of these solutions work in both Lucee and Adobe ColdFusion due to the differences in Java package bundling approaches between the two engines.",[10,489,490],{},"The best we can get would be something like this:",[31,492,494],{"className":101,"code":493,"language":103,"meta":36,"style":36},"\u002F**\n * Grab installed version of the bundled Apache POI library.\n *\u002F\npublic string function getApachePOIVersion(){\n    if ( server.system.keyExists( \"lucee\" ) ){\n        createObject( \"java\", \"org.apache.poi.hssf.usermodel.HSSFSheet\" )\n            .getClass()\n            .getClassLoader()\n            .getBundle()\n            .getVersion()\n            .toString()\n    } else {\n        return createObject( \"java\", \"java.lang.Package\" )\n                            .getPackage( \"org.apache.poi\" )\n                            .getImplementationVersion();\n    }\n}\n",[38,495,496,502,507,512,526,545,560,569,578,587,596,605,617,635,649,658,664],{"__ignoreMap":36},[41,497,498],{"class":43,"line":44},[41,499,501],{"class":500},"sJ8bj","\u002F**\n",[41,503,504],{"class":43,"line":150},[41,505,506],{"class":500}," * Grab installed version of the bundled Apache POI library.\n",[41,508,509],{"class":43,"line":162},[41,510,511],{"class":500}," *\u002F\n",[41,513,514,517,520,523],{"class":43,"line":210},[41,515,516],{"class":64},"public string ",[41,518,519],{"class":230},"function",[41,521,522],{"class":47}," getApachePOIVersion",[41,524,525],{"class":64},"(){\n",[41,527,528,531,534,537,539,542],{"class":43,"line":277},[41,529,530],{"class":230},"    if",[41,532,533],{"class":64}," ( server.system.",[41,535,536],{"class":47},"keyExists",[41,538,113],{"class":64},[41,540,541],{"class":51},"\"lucee\"",[41,543,544],{"class":64}," ) ){\n",[41,546,547,550,552,554,556,558],{"class":43,"line":287},[41,548,549],{"class":47},"        createObject",[41,551,113],{"class":64},[41,553,116],{"class":51},[41,555,119],{"class":64},[41,557,122],{"class":51},[41,559,125],{"class":64},[41,561,563,565,567],{"class":43,"line":562},7,[41,564,416],{"class":64},[41,566,156],{"class":47},[41,568,159],{"class":64},[41,570,572,574,576],{"class":43,"line":571},8,[41,573,416],{"class":64},[41,575,167],{"class":47},[41,577,159],{"class":64},[41,579,581,583,585],{"class":43,"line":580},9,[41,582,416],{"class":64},[41,584,215],{"class":47},[41,586,159],{"class":64},[41,588,590,592,594],{"class":43,"line":589},10,[41,591,416],{"class":64},[41,593,282],{"class":47},[41,595,159],{"class":64},[41,597,599,601,603],{"class":43,"line":598},11,[41,600,416],{"class":64},[41,602,292],{"class":47},[41,604,159],{"class":64},[41,606,608,611,614],{"class":43,"line":607},12,[41,609,610],{"class":64},"    } ",[41,612,613],{"class":230},"else",[41,615,616],{"class":64}," {\n",[41,618,620,623,625,627,629,631,633],{"class":43,"line":619},13,[41,621,622],{"class":230},"        return",[41,624,240],{"class":47},[41,626,113],{"class":64},[41,628,116],{"class":51},[41,630,119],{"class":64},[41,632,386],{"class":51},[41,634,125],{"class":64},[41,636,638,641,643,645,647],{"class":43,"line":637},14,[41,639,640],{"class":64},"                            .",[41,642,419],{"class":47},[41,644,113],{"class":64},[41,646,424],{"class":51},[41,648,125],{"class":64},[41,650,652,654,656],{"class":43,"line":651},15,[41,653,640],{"class":64},[41,655,474],{"class":47},[41,657,477],{"class":64},[41,659,661],{"class":43,"line":660},16,[41,662,663],{"class":64},"    }\n",[41,665,667],{"class":43,"line":666},17,[41,668,669],{"class":64},"}\n",[10,671,672,673,676],{},"Sadly, I see little hope for a cross-engine solution that works ",[78,674,675],{},"generically"," on package names. In Adobe you can grab the package version by package name… but in Lucee you must search for a specific package class.",[92,678,680],{"id":679},"the-poi-version-class","The POI Version Class",[10,682,683],{},"Caveat: Apache POI ships with a “Version” class in versions 3.x. So my example is a bit pointless for Apache POI v3 and newer. If you’re on ACF 10+, you can use the provided Version class to grab the version - no Java Package gymnastics required:",[31,685,687],{"className":101,"code":686,"language":103,"meta":36,"style":36},"    createObject( \"java\", \"org.apache.poi.Version\" ).getVersion()\n",[38,688,689],{"__ignoreMap":36},[41,690,691,694,696,698,700,703,706,708],{"class":43,"line":44},[41,692,693],{"class":47},"    createObject",[41,695,113],{"class":64},[41,697,116],{"class":51},[41,699,119],{"class":64},[41,701,702],{"class":51},"\"org.apache.poi.Version\"",[41,704,705],{"class":64}," ).",[41,707,282],{"class":47},[41,709,159],{"class":64},[10,711,712,713,716,717,720],{},"That’s not the point of this blog post, though. This post aims to assist you in reading the installed version of ",[301,714,715],{},"any Java package"," - not just those with a handy ",[38,718,719],{},"my.package.Version"," class.",[10,722,723],{},"Till next time!",[725,726,727],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":36,"searchDepth":150,"depth":150,"links":729},[730,733,734,735],{"id":94,"depth":150,"text":95,"children":731},[732],{"id":308,"depth":162,"text":309},{"id":361,"depth":150,"text":362},{"id":483,"depth":150,"text":484},{"id":679,"depth":150,"text":680},"2022-09-21T16:13:57-04:00","The Apache POI library is an awesome tool for messing with spreadsheets. You can read spreadsheet data, get header rows, total row count, all sorts of wacky stuff. Julian Halliwell's excellent spreadsheet-cfml library uses it to great effect.",false,"md",{},true,"\u002Fposts\u002Fread-java-package-version",{"title":5,"description":737},"posts\u002Fread-java-package-version",[746,747,748],"cfml","coldfusion","java","Zy_tpcuvlkTwQbOiaNzbaL8q1qyONTpkmquyUaIHksk",1790471527454]