javac:包 org.apache.poi.hssf.usermodel 不存在
我有一个程序试图使用 /usr/share/java 目录中 jakarta-poi-3.0.2.jar 中的类:
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
etc...
编译时,我得到一个包 org.apache上述每个导入都会出现 .poi.hssf.usermodel 不存在 错误。
我的类路径中有 /usr/share/java 。我还遗漏了什么吗?
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
error for each of the imports above.
I have /usr/share/java on my classpath. Am I missing anything else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
类路径上的 /usr/share/java 不会引入 /usr/share/java 中的所有 jar。
尝试将 /usr/share/java/jakarta-poi-3.0.2.jar 放入类路径中。
/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.
首先,您可能想要升级 - Apache POI 3.0.2 已经有 3 年多了,并且已经有 a从那时起,进行了很多修复!
至于您的问题,您要么需要在类路径上单独列出每个 jar 文件,要么需要将所有 jar 文件放入 jre lib 目录中(内容是自动包含的)。不过,通常不建议使用后者...
您不能只在类路径上列出一个目录,然后从其中提取 jar,抱歉。只会从类路径目录中加载单个类文件,而不会加载 jar 文件
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
引导类路径是 $JAVA_HOME/lib
但对于用户应用程序,请使用用户类路径设置 -classpath 参数,如下所示:
java -classpath /usr/share/java/myclasses.jar
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
以下解决方案帮助了我
类路径是Java运行时环境搜索类和其他资源文件的路径。类搜索路径(更常见的名称是“类路径”)可以在调用 JDK 工具时使用 -classpath 选项(首选方法)进行设置,也可以通过设置 CLASSPATH 环境变量进行设置。 -classpath 选项是首选,因为您可以为每个应用程序单独设置它,而不会影响其他应用程序,也不会其他应用程序修改其值。
C:> sdkTool -classpath classpath1;classpath2...
-或-
C:>设置 CLASSPATH=classpath1;classpath2...
其中:
sdkTool
命令行工具,例如 java、javac、javadoc 或 apt。有关列表,请参阅 JDK 工具。
classpath1;classpath2 .jar、.zip 或 .class 文件的类路径。每个类路径应以文件名或目录结尾,具体取决于您将类路径设置为:
对于包含 .class 文件的 .jar 或 .zip 文件,类路径以 .zip 或 .jar 文件的名称结尾。
对于未命名包中的 .class 文件,类路径以包含 .class 文件的目录结尾。
对于命名包中的 .class 文件,类路径以包含“根”包(完整包名称中的第一个包)的目录结尾。
多个路径条目以分号分隔。使用 set 命令时,省略等号 (=) 周围的空格非常重要。
默认类路径是当前目录。设置 CLASSPATH 变量或使用 -classpath 命令行选项会覆盖该默认值,因此如果要在搜索路径中包含当前目录,则必须包含“.”。在新的设置中。
既不是目录也不是档案(.zip 或 .jar 文件)也不是 * 的类路径条目将被忽略。
参考:http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
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