Skip navigation
Currently Being Moderated

Java class in ColdFusion

Dec 19, 2013 9:53 PM

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.

 
Replies
  • Currently Being Moderated
    Dec 21, 2013 4:37 AM   in reply to Abdul L Koyappayil

    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.

     

     

     


     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points