I am trying to parse a CSV File with Coldfusion and a JavaLibrary. I found some examples but it seems that ColdFusion cannot find the Jar-File.
This is my Code:
<cfset t01= getTickCount()>
<cfscript>
fileReader = createobject("java","java.io.FileReader");
fileReader.init("C:\Dev\files.csv");
csvReader = createObject("java","au.com.bytecode.opencsv.CSVReader");
csvReader.init(fileReader, ",");
</cfscript>
<cfset t02= getTickCount()>
<cfset ArrayData = csvReader.readAll()>
<cfset t03= getTickCount()>
<cfoutput>
Process Data: #t02 - t01# ms
Display Dump: #t03 - t02# ms
<cfdump var="ArrayData"><cfabort />
</cfoutput>
and this is the ErrorMessage:
java.lang.ClassNotFoundException: au.com.bytecode.opencsv.CSVReader
at coldfusion.bootstrap.BootstrapClassLoader.loadClass(BootstrapClassLoader.java:235)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248).....more Stack blabla......
I am using the opencsv Library. The Jar File is in the following folder:
wwwroot/WEB-INF/lib
I also restarted the Server multiple times.
Thanks for your help!
I downloaded the opencsv jar file and it looks like you might be referencing it incorrectly.
Instead of this:
csvReader = createObject("java","au.com.bytecode.opencsv.CSVReader");
Try this:
csvReader = createObject("java","com.opencsv.CSVReader");
I was looking at the latest version, 3.3, but I assume that hasn't changed.
From the comments (my assumption was incorrect)
As Leigh pointed out in the comments, older versions of the opencsv library used a different package name than the latest version does. Old versions used au.com.bytecode.opencsv
but the new versions use com.opencsv
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With