设置类路径的文件夹

发布于 2024-12-29 18:29:52 字数 107 浏览 1 评论 0原文

在命令行中,如何设置 Java CLASSPATH 选项以指向一个或多个包含多个 jar 文件的目录?是否有递归目录和子目录支持的通配符?

(我的 JAR 文件分类在几个子目录中。)

From the command line, how do I set the Java CLASSPATH option to point to one or more directories containing multiple jar file? Are there wildcards for recursive directory and sub-directory support?

(My JAR files are sorted in several sub-directories.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡风轻 2025-01-05 18:29:52

如果您使用的是 Java 6 或更高版本,则可以使用以下形式的通配符:

java -classpath ".;c:\mylibs\*;c:\extlibs\*" MyApp

如果您想添加所有子目录:lib\a\、lib\b\、lib\c\,则没有任何机制,除了

java -classpath ".;c:\lib\a\*;c:\lib\b\*;c:\lib\c\*" MyApp

:与您想要完成的工作类型的 lib\*\*lib\** 通配符不同。

If you are using Java 6 or higher you can use wildcards of this form:

java -classpath ".;c:\mylibs\*;c:\extlibs\*" MyApp

If you would like to add all subdirectories: lib\a\, lib\b\, lib\c\, there is no mechanism for this in except:

java -classpath ".;c:\lib\a\*;c:\lib\b\*;c:\lib\c\*" MyApp

There is nothing like lib\*\* or lib\** wildcard for the kind of job you want to be done.

江南月 2025-01-05 18:29:52

使用命令为

java -classpath ".;C:\MyLibs\a\*;D:\MyLibs\b\*" <your-class-name>

上面的命令只会将提到的路径设置为类路径一次,以执行名为 TestClass 的类。

如果您想执行多个类,那么您可以按照此操作

set classpath=".;C:\MyLibs\a\*;D:\MyLibs\b\*"

之后,您只需输入即可执行任意多个类。

java <your-class-name>

上面的命令将一直有效,直到您关闭命令提示符为止。但是关闭命令提示符后,如果您将重新打开命令提示符并尝试执行某些类,那么您必须借助上述两种方法中的任何一种再次设置类路径。(第一种方法用于执行一个类,第二种方法用于执行一个类)一个用于执行更多类)

如果您只想设置 classpth 一次以便它每次都可以工作,那么请执行以下操作

1. Right click on "My Computer" icon
2. Go to the "properties"
3. Go to the "Advanced System Settings" or "Advance Settings"
4. Go to the "Environment Variable"
5. Create a new variable at the user variable by giving the information as below
    a.  Variable Name-     classpath
    b.  Variable Value-    .;C:\program files\jdk 1.6.0\bin;C:\MyLibs\a\';C:\MyLibs\b\*
6.Apply this and you are done.

记住这每次都会工作。您不需要一次又一次显式设置类路径。

注意:如果您想在某一天后添加其他库,请不要忘记在“环境变量”的“变量值”末尾添加分号,然后输入新库的路径分号之后。因为分号分隔不同目录的路径。

希望这会对您有所帮助。

Use the command as

java -classpath ".;C:\MyLibs\a\*;D:\MyLibs\b\*" <your-class-name>

The above command will set the mentioned paths to classpath only once for executing the class named TestClass.

If you want to execute more then one classes, then you can follow this

set classpath=".;C:\MyLibs\a\*;D:\MyLibs\b\*"

After this you can execute as many classes as you want just by simply typing

java <your-class-name>

The above command will work till you close the command prompt. But after closing the command prompt, if you will reopen the command prompt and try to execute some classes, then you have to again set the classpath with the help of any of the above two mentioned methods.(First method for executing one class and second one for executing more classes)

If you want to set the classpth only once so that it could work for everytime, then do as follows

1. Right click on "My Computer" icon
2. Go to the "properties"
3. Go to the "Advanced System Settings" or "Advance Settings"
4. Go to the "Environment Variable"
5. Create a new variable at the user variable by giving the information as below
    a.  Variable Name-     classpath
    b.  Variable Value-    .;C:\program files\jdk 1.6.0\bin;C:\MyLibs\a\';C:\MyLibs\b\*
6.Apply this and you are done.

Remember this will work every time. You don't need to explicitly set the classpath again and again.

NOTE: If you want to add some other libs after some day, then don't forget to add a semi-colon at the end of the "variable-value" of the "Environment Variable" and then type the path of your new libs after the semi-colon. Because semi-colon separates the paths of different directories.

Hope this will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文