将 .jar 文件包含在类路径中
我正在尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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\
andC:\java\specialclasses\
and two jar filesC:\java\jars\jam.jar
andC:\java\jars\jelly.jar
then your class path variable would be set toC:\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.
只需查看 Oracle 自己的文档
例如,如果如果 /a/directory 中有 3 个 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:
You would set the CLASSPATH variable in a similar fashion.