Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion/Java Class not found Exception

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!

like image 926
noah Avatar asked Apr 17 '15 05:04

noah


1 Answers

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.

like image 138
Miguel-F Avatar answered Oct 01 '22 23:10

Miguel-F