如何在Java中设置类路径? [英] How to set the classpath in Java?

查看:122
本文介绍了如何在Java中设置类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多jar文件要添加到我的类路径中,所以每次编译Java文件时,都会以如下命令结束:

I've many jar files to add to my classpath, so everytime I compile my java file I end up with a command like this:

javac -cp commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar:commons-logging-1.1.1/commons-logging-1.1.1.jar:commons-beanutils-core-1.7.0.jar:. CollectionIndexer.java

我尝试使用:

set CLASSPATH=commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar:commons-logging-1.1.1/commons-logging-1.1.1.jar:commons-beanutils-core-1.7.0.jar:.

然后:

javac CollectionIndexer.java

但根本不添加jar:我得到了由于缺少jar而导致错误...
谢谢

but the jar are not added at all: I get error due to the missing jars... thanks

推荐答案

也许您想尝试使用Maven来构建应用?
这真的很容易设置,并且可以消除依赖管理中的所有问题。

maybe you want to try to use maven for build you application? It's really easy to setup and it annihilate all problems with dependency management.

也可以从Java 6中在类路径中使用通配符:
set CLASSPATH = my_libs\ *;

also from java 6 you can use wildcards in classpath: set CLASSPATH=my_libs\*;

这篇关于如何在Java中设置类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆