【问题标题】:Add custome utility JAR to Windows System Path将自定义实用程序 JAR 添加到 Windows 系统路径
【发布时间】:2026-02-17 09:30:01
【问题描述】:

是否可以将实用程序 jar 添加到 Window 的系统路径?

我有findclass.jar,这是一个位于我的C:\ 目录中的可执行jar。
如果我打开 cmd.exe,将目录更改为 C:\,然后输入:
java -jar findclass.jar \path\tojar.jar nameofclass.class
它将在另一个 jar 中搜索给定的类。

如何将 findclass.jar 添加到我的 Window 的系统路径中,这样我就不需要将目录更改为 C:\
我试过set path=C:\;%PATH%set path=C:\findclass.jar;%PATH%
但是当我尝试从不同的目录执行它时,我得到了Error: Unable to access jarfile findclass.jar

不能在路径中添加.jar文件吗?

【问题讨论】:

    标签: java windows jar path


    【解决方案1】:

    将其添加到 CLASSPATH 环境变量中。

    【讨论】:

    • 仍然收到Error: Unable to access jarfile findclass.jar
    • >set classpath=C:\findclass.jar;%CLASSPATH% > java -jar findclass.jar \path\tojar.jar nameofclass.class 仍然会导致 >Error: Unable to access jarfile findclass.jar 除非我 cd 进入 C:\