开发者

javac: package org.apache.poi.hssf.usermodel does not exist

I have a program attempting to use classes from the jakarta-poi-3.0.2.jar in my /usr/share/java directory:

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
etc...

When I compile, I get a package org.apache.poi.hssf.usermodel does not exist erro开发者_运维问答r for each of the imports above.

I have /usr/share/java on my classpath. Am I missing anything else?


/usr/share/java on the classpath does not bring in all jars in /usr/share/java.

Try putting /usr/share/java/jakarta-poi-3.0.2.jar in your classpath instead.


First up, you might want to upgrade - Apache POI 3.0.2 is over 3 years old, and there have been a lot of fixes since then!

As for your issue, you either need to list each jar file individually on your classpath, or you need to place all your jars into the jre lib directory (the contents is which is automatically included). The latter isn't generally recommended though...

You can't just list a directory on the classpath, and have the jars from within it picked up, sorry. Only individual class files will be loaded from a classpath directory, jars won't be


Bootstrap classpath is $JAVA_HOME/lib but for user applications use user classpaths setting -classpath parameter like that: java -classpath /usr/share/java/myclasses.jar


The following solution helped me

The class path is the path that the Java runtime environment searches for classes and other resource files. The class search path (more commonly known by the shorter name, "class path") can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.

C:> sdkTool -classpath classpath1;classpath2...

-or-

C:> set CLASSPATH=classpath1;classpath2...

where:

sdkTool A command-line tool, such as java, javac, javadoc, or apt. For a listing, see JDK Tools.

classpath1;classpath2 Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to: For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file. For .class files in an unnamed package, the class path ends with the directory that contains the .class files. For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name). Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

Classpath entries that are neither directories nor archives (.zip or .jar files) nor * are ignored.

Reference :http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜