1 Reply Latest reply on Dec 21, 2013 4:37 AM by Upen@Roul

    Java class in ColdFusion

    Abdul L Koyappayil Level 1

      Hello All,


      I have a java code to read excel sheet with more than 15000 rows of data. But any one have any idea about how to use the java class in coldfusion. So that I can create an object in coldfusion using CreateObject function and hence I can use the method inside java class to read the excel.


      Please help me by providing an example , it would be well appreciated.


      Thanks in advance.

        • 1. Re: Java class in ColdFusion
          Upen@Roul Level 1

          You can do this in 3 ways:


          1.Put your java class/jar file directly into "{CFRoot}\cfusion\lib\" then restart your ColdFusion server and create java object like below:


          <cfset javaObj = createObject("java", "org.owasp.validator.html.AntiSamy") />

          <cfset scanResult = javaObj.scan("<script>alert('xss 1');</script>", expandPath('./antisamy-slashdot-1.4.4.xml')) />

          Above code is just an example of another java library.


          2. Use ColdFusion java library to load class or jar files. You don't have to put your class file in ColdFusion installation, you can keep your class file in your project directory. If you want to know how to use javaloader then refer the URL:https://github.com/markmandel/JavaLoader

          then use the code which I have written above to create object of your class file and call the function which you wants.


          3. In ColdFusion 10, adobe has integrated javaloader. So, you don't have to use any javaloader by your own but you have to make the following set up in Application.cfc.


          this.javaSettings = {

                              loadPaths = ["/lib"], //Path of the folder where you are keeping the library. This is relative path.

                              loadColdFusionClassPath = true,

                              reloadOnChange = true,

                              watchInterval = 10000,

                              watchExtensions = "jar,class,xml"



          Then execute the #1 code to create java object and call the methods present in that class.



          NOTE: #3 only will work in CF10 and higher and #1 and #3 will work for CF7 and higher version.