Set path for Apache POI

我是研究僧i 提交于 2019-12-20 04:27:26

问题


I want to create excel file and write data in that file using java program.

That is here and i extracted Apache POI in location where java file is present.and include that path in path variable.

when i try to compile its giving following error:

data.java:3: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFCell;
                                    ^
data.java:4: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
                                    ^
data.java:5: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
                                    ^
data.java:6: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFRow;
                                    ^
data.java:7: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFSheet;
                                    ^
data.java:8: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
                                    ^
data.java:11: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFFont;
                                    ^
data.java:12: package org.apache.poi.ss.usermodel does not exist
import org.apache.poi.ss.usermodel.IndexedColors;
                              ^

this is list of Poi files.in this which one i have to include ?

root@:[/u01/isac/code/CWSA/isac/java/exportAPI/poi-3.9]

$ ll    

total 9044    

-rw-r--r--  1 root root   27138 Nov 25 15:23 LICENSE    
-rw-r--r--  1 root root     890 Nov 25 15:23 NOTICE    
drwxr-xr-x 16 root root    4096 Nov 26 17:22 docs    
drwxr-xr-x  2 root root    4096 Nov 26 17:22 lib    
drwxr-xr-x  2 root root    4096 Nov 26 17:22 ooxml-lib    
-rw-r--r--  1 root root 1869113 Nov 26 17:22 poi-3.9-20121203.jar    
-rw-r--r--  1 root root  309368 Nov 26 17:22 poi-examples-3.9-20121203.jar    
-rw-r--r--  1 root root   30446 Nov 26 17:22 poi-excelant-3.9-20121203.jar    
-rw-r--r--  1 root root  936648 Nov 26 17:22 poi-ooxml-3.9-20121203.jar    
-rw-r--r--  1 root root 4802621 Nov 26 17:22 poi-ooxml-schemas-3.9-20121203.jar    
-rw-r--r--  1 root root 1226511 Nov 26 17:22 poi-scratchpad-3.9-20121203.jar

回答1:


You should specify the jar location in the -cp option of javac:

javac -cp /path/to/your/jar/poi-<version>.jar data.java

Besides, you may want to use a build tool to manage your dependency, e.g. maven or ivy for ant.




回答2:


You have to put the jar files (poi lib) in your classpath, not the same directory with your data.java. (btw, it should be Data.java). Because you very likely have your own package structure, like com.myapp.

And the PATH variable has nothing to do with java classpath. it makes no difference if you set or unset it.



来源:https://stackoverflow.com/questions/14562817/set-path-for-apache-poi

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