ColdFusion / Java class not found Exception

I am trying to parse a CSV file with Coldfusion and 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 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 opencsv library . The jar file is located in the following folder:

Wwwroot / WEB-INF / Library

I also restarted the Server several times.

Thank you for your help!

+6
source share
1 answer

I downloaded the opencsv jar file and it looks like you may be referencing it incorrectly.

Instead of this:

 csvReader = createObject("java","au.com.bytecode.opencsv.CSVReader"); 

Try the following:

 csvReader = createObject("java","com.opencsv.CSVReader"); 

I watched the latest version, 3.3, but I assume that it has not changed.

From the comments (my assumption was wrong)

As Lee noted in the comments, older versions of the opencsv library used a different package name than the latest version. Older versions use au.com.bytecode.opencsv , but newer versions use com.opencsv .

+2
source

Source: https://habr.com/ru/post/985320/


All Articles