Javac无法找到apache commons config的jar

时间:2009-06-07 23:14:52

标签: java linux command-line compilation

我正在尝试使用Apache Commons Config jar在Ubuntu Jaunty上编译一个非常简单的Java 1.6程序。我一直得到“包org.apache.commons.configuration不存在”错误,即使jar在同一目录中。有什么想法吗?

  • 目录列表
~/source/UpdateStockHistory$ ll
total 304
-rw-r--r-- 1 crosse crosse 298829 2009-06-07 17:36 commons-configuration-1.6.jar
-rw-r--r-- 1 crosse crosse    149 2009-06-07 17:16 UpdateStockHistory.config.xml
-rw-r--r-- 1 crosse crosse    531 2009-06-07 17:46 UpdateStockHistory.java
  • Java版本
~/source/UpdateStockHistory$ javac -version
javac 1.6.0_13
  • 操作系统版本
~/source/UpdateStockHistory$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 9.04
Release:        9.04
Codename:       jaunty
  • 编译器版本
~/source/UpdateStockHistory$ javac UpdateStockHistory.java
UpdateStockHistory.java:2: package org.apache.commons.configuration does not exist
import org.apache.commons.configuration.*;
^
UpdateStockHistory.java:8: cannot find symbol
symbol  : class ConfigurationFactory
location: class com.crosse.tradingresearch.UpdateStockHistory
                        ConfigurationFactory factory = new ConfigurationFactory("UpdateStockHistory.config.xml");
                        ^
UpdateStockHistory.java:8: cannot find symbol
symbol  : class ConfigurationFactory
location: class com.crosse.tradingresearch.UpdateStockHistory
                        ConfigurationFactory factory = new ConfigurationFactory("UpdateStockHistory.config.xml");
                                                           ^
UpdateStockHistory.java:9: cannot find symbol
symbol  : class Configuration
location: class com.crosse.tradingresearch.UpdateStockHistory
                        Configuration config = factory.getConfiguration();
                        ^
4 errors

讨厌问这样一个“为我做这件事”的问题,但我已经没想到了。

2 个答案:

答案 0 :(得分:6)

尝试将jar添加到类路径中,如下所示:

javac UpdateStockHistory.java -cp commons-configuration-1.6.jar

答案 1 :(得分:2)

Javac不会自动在当前目录中搜索类。您可以告诉它使用:

javac -cp . UpdateStockHistory.java