将 .jar 文件包含在类路径中

发布于 2024-12-28 07:37:46 字数 169 浏览 2 评论 0原文

我正在尝试在 Windows 环境中启动并运行 JDBC。在类路径中包含 .jar 文件意味着什么?我看到如何修改 Windows 的 CLASSPATH 环境变量...但是哪些文件需要放在哪里以及 CLASSPATH 环境变量需要设置为什么?我已经尝试了几乎所有我能立即想到的组合,但我却不知所措。

谢谢。

I'm trying to get JDBC up and running in the Windows environment. What does it mean to include a .jar file in the classpath? I see how to modify the CLASSPATH environment variable for Windows... But what files need to go where and what does the CLASSPATH environment variable need to be set to? I've tried just about every combination that I can immediately think of, and I'm at a loss.

Thanks.

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

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

发布评论

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

评论(2

岁月无声 2025-01-04 07:37:46

CLASSPATH 变量包含可找到类文件的目录列表。 .jar 文件实际上是一个压缩目录,因此 .jar 文件本身的名称应该位于 CLASSPATH 中,而不是它所在目录的名称。

例如,如果您有两个目录,其中包含类文件树它们 C:\java\classes\C:\java\specialclasses\ 以及两个 jar 文件 C:\java\jars\jam.jar > 和C:\java\jars\jelly.jar 那么你的类路径变量将被设置为 C:\java\classes\;C:\java\specialclasses\;C:\java\ jars\jam.jar;C:\java\jars\jelly.jar

作为一般规则,除非您有两个具有相同名称的类的包(希望您没有),那么您只想将常用的东西添加到CLASSPATH 变量,而不是删除或替换已经存在的东西。默认情况下,它包含 java.* 类的目录,包含这些目录很重要。此外,根据您的环境,管理员可能已添加其他常用的类。

The CLASSPATH variable contains a list of directories where class files are found. A .jar file is really a zipped up directory, so the name of the .jar file itself should be in the CLASSPATH, not the name of the directory it is in.

If, for example, you had two directories with class file trees in them C:\java\classes\ and C:\java\specialclasses\ and two jar files C:\java\jars\jam.jar and C:\java\jars\jelly.jar then your class path variable would be set to C:\java\classes\;C:\java\specialclasses\;C:\java\jars\jam.jar;C:\java\jars\jelly.jar

As a general rule, unless you have two packages with classes with the same name (which hopefully you don't), then you just want to add things that are going to commonly be used to the CLASSPATH variable and not remove or replace things which are already there. By default, it includes the directories of the java.* classes, which are kind of important to include. Also, depending on your environment, other commonly used classes may have been added by an administrator.

尹雨沫 2025-01-04 07:37:46

只需查看 Oracle 自己的文档

例如,如果如果 /a/directory 中有 3 个 jar,您将执行以下操作:

java -classpath /a/directory/jar1.jar;/a/directory/jar2.jar;/a/directory/jar3.jar

您将以类似的方式设置 CLASSPATH 变量。

Look no further than Oracle's own documentation

For instance, if you had 3 jars in /a/directory, you would do something like:

java -classpath /a/directory/jar1.jar;/a/directory/jar2.jar;/a/directory/jar3.jar

You would set the CLASSPATH variable in a similar fashion.

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