Reputation: 201
I'm trying to implement reading from .xls file. I have the following code:
FileInputStream file = null;
Workbook workbook = null;
try {
file = new FileInputStream(System.getProperty("user.home") + "/Downloads/" + fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (fileName.endsWith(".xls")) {
try {
**workbook = new HSSFWorkbook(file);**
} catch (IOException e) {
e.printStackTrace();
}
This marked code line crashes.
I imported in pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.0</version>
</dependency>
but I got the error: Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream
I would appreciate help on this. Thanks.
Upvotes: 18
Views: 75699
Reputation: 151
Changed all dependencies to last version and it works for me:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency>
Upvotes: 0
Reputation: 670
I landed here because of the following error
NoClassDefFoundError org/apache/commons/io/function/Uncheck
Apparently the root cause is the same. Some dependancies have changed (in my case, for Apache CSV, on an integration with Spring Shell, if that's important..) (Note that the solution below is guided by some suggestions on this thread.)
Solution was to change from Apache Commons IO from 2.11.0
to 2.16.1
:
Hope this helps somebody.
In case, if someone is interested on the full list of library changes, they are as follows:
Before:
<properties>
<spring-shell.version>3.2.4</spring-shell.version>
<apache-commons-io.version>2.11.0</apache-commons-io.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
<apache-commons-text.version>1.12.0</apache-commons-text.version>
<apache-commons-logging.version>1.3.1</apache-commons-logging.version>
<apache-commons-collections4.version>4.4</apache-commons-collections4.version>
<apache-commons-csv.version>1.11.0</apache-commons-csv.version>
</properties>
After:
<properties>
<spring-shell.version>3.2.4</spring-shell.version>
<apache-commons-io.version>2.16.1</apache-commons-io.version>
<apache-commons-lang3.version>3.14.0</apache-commons-lang3.version>
<apache-commons-text.version>1.12.0</apache-commons-text.version>
<apache-commons-logging.version>1.3.1</apache-commons-logging.version>
<apache-commons-collections4.version>4.5.0-M1</apache-commons-collections4.version>
<apache-commons-csv.version>1.11.0</apache-commons-csv.version>
</properties>
Upvotes: 0
Reputation: 21
Works for me:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
Upvotes: 1
Reputation: 11
This issue is resolved with following dependencies: [Dependencies]
Upvotes: 0
Reputation: 240
Looks like you don't have commons-io dependency. please add this dependency
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
Upvotes: 4
Reputation: 91
I recently upgraded Apache POI to 5.2.3 and was having the same ClassNotFoundException. Since the application was working fine before the upgrade, so I quickly did three things to debug:
Once I added the latest available Apache Commons IO 2.11.0 to my maven pom.xml and rebuild the application, the problem solved. I hope this help!
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
Upvotes: 9
Reputation: 33
It worked for me by removing this dependency
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
Upvotes: 1
Reputation: 181
It worked for me
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
Upvotes: 18
Reputation: 21
When I read excel to XSSFWorkbook, it prompt error message that "commons.io.output.UnsynchronizedByteArrayOutputStream" finally fixed it by downgrad the version of poi from 5.2.3 to 5.2.2
Upvotes: 2
Reputation: 57
Change the dependency to
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
I used the version 5.2.0 as well and was getting the same error and changing that fixed it.
Upvotes: 4
Reputation: 2922
Add
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
to you pom
Upvotes: 6