I'm trying to run a Lucene Java application on my local machine. I get this compilation开发者_运维知识库 error:
package org.apache.commons.digester does not exist
because of
import org.apache.commons.digester.Digester;
Isn't the compiler downloading the package from the Internet? If not, what should I do?
No, the compiler doesn't download packages from the Internet. Some build management tools like Maven do it if you configure them properly and add the package to the project dependencies. But without such a tool you should download the jar manually and put it on the compiler classpath.
If you are using Maven you could download the lib by adding the following dependency:
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
Else you have to download it here. Then just add the .jar to your Buildpath.
If you are using maven and added this as dependency then it will download it for you. otherwise
You can download it from here , appropriate version. and add it to your app's class path
No the compiler does not download packages from the internet when you import them. The naming convention for packages makes them appear like URLs but they are not and the compiler certainly makes no attempt to download dependencies.
The idea is that if all creators of Java libraries conform to this convention and use their domain name in package names then class name clashes between libraries from different authors can be avoided. However as previously stated this just a naming convention and has relationship to dependency management.
Some build tools like Maven have sophisticated and relatively easy to use dependency management mechanisms. The popular Ant build tool also has this capability through the Ivy dependency manager.
精彩评论