javac: 包 org.apache.poi.hssf.usermodel 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4209553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javac: package org.apache.poi.hssf.usermodel does not exist
提问by Max
I have a program attempting to use classes from the jakarta-poi-3.0.2.jar
in my /usr/share/java directory:
我有一个程序试图使用jakarta-poi-3.0.2.jar
我的 /usr/share/java 目录中的类:
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.
当我编译时,package org.apache.poi.hssf.usermodel does not exist
上面的每个导入都会出错。
I have /usr/share/java on my classpath. Am I missing anything else?
我的类路径上有 /usr/share/java 。我还缺什么吗?
采纳答案by Thorbj?rn Ravn Andersen
/usr/share/java on the classpath does not bring in all jars in /usr/share/java.
类路径上的 /usr/share/java 不会引入 /usr/share/java 中的所有 jar。
Try putting /usr/share/java/jakarta-poi-3.0.2.jar in your classpath instead.
尝试将 /usr/share/java/jakarta-poi-3.0.2.jar 放在您的类路径中。
回答by Erhan Bagdemir
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
Bootstrap 类路径是 $JAVA_HOME/lib 但对于用户应用程序使用用户类路径设置 -classpath 参数如下: java -classpath /usr/share/java/myclasses.jar
回答by Harz
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.
类路径是 Java 运行时环境搜索类和其他资源文件的路径。可以在调用 JDK 工具(首选方法)时使用 -classpath 选项或通过设置 CLASSPATH 环境变量来设置类搜索路径(更常见的是较短的名称“类路径”)。-classpath 选项是首选,因为您可以为每个应用程序单独设置它,而不会影响其他应用程序,也无需其他应用程序修改其值。
C:> sdkTool -classpath classpath1;classpath2...
C:> sdkTool -classpath classpath1;classpath2...
-or-
-或者-
C:> set CLASSPATH=classpath1;classpath2...
C:> 设置 CLASSPATH=classpath1;classpath2...
where:
在哪里:
sdkToolA command-line tool, such as java, javac, javadoc, or apt. For a listing, see JDK Tools.
sdkTool命令行工具,例如 java、javac、javadoc 或 apt。有关列表,请参阅 JDK 工具。
classpath1;classpath2Class 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 (=).
classpath1;classpath2.jar、.zip 或 .class 文件的类路径。每个类路径都应以文件名或目录结尾,具体取决于您将类路径设置为什么: 对于包含 .class 文件的 .jar 或 .zip 文件,类路径以 .zip 或 .jar 文件的名称结尾。对于未命名包中的 .class 文件,类路径以包含 .class 文件的目录结尾。对于命名包中的 .class 文件,类路径以包含“根”包(完整包名称中的第一个包)的目录结尾。多个路径条目用分号分隔。使用 set 命令时,省略等号 (=) 周围的空格很重要。
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 变量或使用 -classpath 命令行选项会覆盖该默认值,因此如果要在搜索路径中包含当前目录,则必须包含“.”。在新设置中。
Classpath entries that are neither directories nor archives (.zip or .jar files) nor * are ignored.
既不是目录也不是档案(.zip 或 .jar 文件)也不是 * 的类路径条目将被忽略。
Reference :http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
参考:http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
回答by Randomness
First up, you might want to upgrade - Apache POI 3.0.2 is over 3 years old, and there have been a lot of fixessince then!
首先,您可能想要升级 - Apache POI 3.0.2 已经 3 年多了,从那时起已经有很多修复!
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...
至于您的问题,您要么需要在类路径上单独列出每个 jar 文件,要么需要将所有 jar 放入 jre lib 目录(内容是自动包含的)。不过一般不推荐后者...
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
抱歉,您不能只在类路径上列出一个目录,然后从其中提取 jar。只会从类路径目录加载单个类文件,不会加载 jars