简体   繁体   English

在 java 类路径中添加一些东西

[英]Add something to the java classpath

I have a jar-File, which I want to add to the classpath, so I ran java -cp ".;C:\Path\to\my\magical\jarfile.jar;.\some\other\directory" MyClass我有一个 jar 文件,我想将它添加到类路径中,所以我运行了 java -cp ".;C:\Path\to\my\magical\jarfile.jar;.\some\other\directory" MyClass

The Problem is: I use some import-commands in my class, an Java doesn't find them anymore, because I replaced the classpath.问题是:我在 class 中使用了一些导入命令,Java 不再找到它们,因为我替换了类路径。 I want just add two elements to the Path.我只想向路径添加两个元素。 How is this posible under Windows?在 Windows 下这怎么可能?

https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html specifies: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html指定:

The default class path is the current directory.默认 class 路径为当前目录。 Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "."设置 CLASSPATH 变量或使用 -classpath 命令行选项会覆盖该默认值,因此如果要在搜索路径中包含当前目录,则必须包含“.”。 in the new settings.在新设置中。

So, to add to that default, include the CLASSPATH environment variable in your invocation:因此,要添加到该默认值,请在您的调用中包含 CLASSPATH 环境变量:

java -cp ".;C:\Path\to\my\magical\jarfile.jar;.\some\other\directory;%CLASSPATH%"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM