I’m trying to use opencsv.jar but I get the error message below.
— Error Message —
No matching Constructor for au.com.bytecode.opencsv.CSVReader(java.io.InputStreamReader, string, string) found
I’ve copied the opencsv.jar to /opt/lucee/tomcat/lucee-server/context/lib and I can see from Lucee Admin that opencsv is “active”.
The code I’m using is as shown below.
---- CF Code —
<cfif IsDefined (“Server.Railo”) AND IsNumeric(Arguments.TextDelimiter)>
<cfset Arguments.TextDelimiter = Evaluate(“chr(#Arguments.TextDelimiter#)”)>
<cfif IsDefined (“Server.Railo”) AND IsNumeric(Arguments.TextQualifier)>
<cfset Arguments.TextQualifier = Evaluate(“chr(#Arguments.TextQualifier#)”)>
// Initialize FileInputStream
InputStream = createobject(“java”,“java.io.FileInputStream”);
InputStream.init(arguments.CSVFilePath);
// Initialize InputStreamReader
objInputReader = createobject(“java”,“java.io.InputStreamReader”);
objInputReader.init(InputStream, arguments.FileEncoding);
// Initialize CSVReader
objCSVReader = createObject(“java”,“au.com.bytecode.opencsv.CSVReader”);
objCSVReader.init(objInputReader, arguments.TextDelimiter, arguments.TextQualifier);
aData = objCSVReader.readAll();
return aData;
I’m able to run the same code without any issues on another server running Lucee 5.2.6.60, Tomcat 8.5.40 and Java 1.8.0_161. Did something change with Lucee 5.3.5.XX? Am I supposed to call the Jar differently?
Also, I tried to use the latest version of OpenCSV (opencsv-5.1.jar) as well. Copied it to the same /opt/lucee/tomcat/lucee-server/context/lib/. However, on Lucee Admin, I see the OpenCSV 5.1 is “loaded” rather than “active”. Then, when I instantiate <cfset MyC = CreateObject(“java”,“com.opencsv”)>, I get the error message below:
— Error Message With OpenCSV-5.1 —
cannot load class through its string name, because no definition for the class with the specified name [com.opencsv] could be found caused by (java.lang.ClassNotFoundException:com.opencsv;java.lang.ClassNotFoundException:com.opencsv not found by lucee.core [46];java.lang.ClassNotFoundException:com.opencsv;)
Thanks for your help!
Charles Tang
Don’t forget to tell us about your stack!
OS: Centos 7.7.1908
Java Version: 1.8.0_161
Tomcat Version: 9.0.31
Lucee Version: 5.3.5.92