简体   繁体   English

我有导入org.apache.commons.io.FileUtils; 在我的代码中,它适用于eclipse但不适用于命令行

[英]I have import org.apache.commons.io.FileUtils; in my code and it works on eclipse but not in command line

I'm using an Apache package; 我正在使用Apache包; I've add it's jar file location to the classpath environment variable. 我将它的jar文件位置添加到classpath环境变量中。 When I try to compile the code via the command line I get numerous errors including: package org.apache.commons.io does not exist 当我尝试通过命令行编译代码时,我收到很多错误,包括:package org.apache.commons.io不存在

You are missing the jar that contains this package (in your case apache-commons.jar) on your classpath. 您在类路径上缺少包含此包的jar(在您的情况下为apache-commons.jar)。

Try to export the packaged jar file with the dependend jars included. 尝试使用包含的dependend jar导出打包的jar文件。 That should work. 这应该工作。

Complile like this: 像这样的Complile:

javac -cp .:common-io-xx.jar YourProgram.java

Run it like this: 像这样运行:

java -cp .:common-io-xx.jar YourProgram

Actually the above option will not work sometimes. 实际上,上述选项有时不起作用。

At run time it might not find the class YourProgram :( Strange but true! 在运行时它可能找不到类YourProgram :(奇怪但真实!

In that case just drop common-io-xx.jar under your ...\\Java\\jdk1\\jre\\lib\\ext 在这种情况下,只需将common-io-xx.jar放在您的... \\ Java \\ jdk1 \\ jre \\ lib \\ ext下

Ofcourse that will work :) Only wasted a few hours to get to that conclusion! 当然会有效:)只浪费了几个小时才得出结论!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Servlet中改善org.apache.commons.io.FileUtils copyInputStreamToFile - How to improve org.apache.commons.io.FileUtils copyInputStreamToFile in Servlet org.apache.commons.io.FileUtils-更改文本编码 - org.apache.commons.io.FileUtils - change text encodig 引起原因:java.lang.ClassNotFoundException:org.apache.commons.io.FileUtils,maven pom.xml wa - Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils, maven pom.xml wa Java库,例如org.apache.commons.io.FileUtils,但包含实例方法而不是静态方法 - Java library like org.apache.commons.io.FileUtils but contains instance methods instead of static methods 使用org.apache.commons.io.FileUtils时Android内存泄漏 - Android memory leak when using org.apache.commons.io.FileUtils 使用Netbeans 8.0.2,并希望使用org.apache.commons.io.FileUtils; 怎么样? - Using Netbeans 8.0.2 and want to use org.apache.commons.io.FileUtils; how? org / apache / commons / io / FileUtils-NoClassDefFoundError - org/apache/commons/io/FileUtils - NoClassDefFoundError 在 org.apache.commons.io.FileUtils.copyURLToFile 上设置超时? - Set timeout on org.apache.commons.io.FileUtils.copyURLToFile? org.apache.commons.io.FileUtils.readFileToString 和文件路径中的空白 - org.apache.commons.io.FileUtils.readFileToString and blanks in filepath 缺少方法 org.apache.commons.io.FileUtils.forceMkdirParent? - missing methode org.apache.commons.io.FileUtils.forceMkdirParent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM