read excel file(which is in classpath ) via apache poi

我与影子孤独终老i 提交于 2019-11-30 20:45:01
user1321466

After spending days on this problem I found an answer in stackoverflow )). FileInputStream vs ClassPathResource vs getResourceAsStream and file integrity

the problem in maven-resources-plugin filtering, it corrupts excel file .

You should not filter binary files like excel and use two mutually exclusive resource sets as described at the bottom of this page 

maven resources plugin

Adding more information to @user1321466 answer, to filter you can do as described in maven resources plugin site:

If you have both text files and binary files as resources it is recommended to have two separated folders. One folder src/main/resources (default) for the resources which are not filtered and another folder src/main/resources-filtered for the resources which are filtered.

or just exclude the files from filtering:

<resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    <excludes>
        <exclude>**/*.xsd</exclude>
        <exclude>**/*.xml</exclude>
    </excludes>
</resource>
<resource>
    <directory>src/main/resources</directory>
    <filtering>false</filtering>
    <includes>
        <include>**/*.xsl</include>
        <include>**/*.xslx</include>
    </includes>
</resource>

Is the file at the top of the classpath, i.e. in WEB-INF/classes?

The API doc for Classloader.getResource() says the resource name is:

"The name of a resource is a '/'-separated path name that identifies the resource."

So if your file is in some subdirectory, that path should be part of the resource name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!