如何在 Ubuntu 中设置临时 Java 类路径
我正在编写一个 Java 程序,我需要设置一个包含我的包的临时类路径。该软件包位于我的 Ubuntu 桌面上,我将其导入为 /home/gaurav/Desktop。你有 知道如何临时设置 Java CLASSPATH 吗?
I am writing a Java program and I need to set a temporary classpath that includes my package. The package is on my Ubuntu desktop, which I am importing as /home/gaurav/Desktop. Do you have
any idea how to set the Java CLASSPATH temporarily?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Ubuntu 上设置 Java 类路径的方式与在任何 Linux / UNIX 平台上设置的方式相同(或者实际上在 Windows 上......模数一些细微的语法差异)。有两种方法:
或
其中
是带有“:”分隔符的路径名序列。欲了解更多详细信息,请参阅“java”命令的手册输入;例如此处和此处。
如果您不明白
export CLASSPATH=...
,请阅读 Ubuntu 的bash
手册条目,注意它关于设置变量、环境变量和bash 的内容。 code>export
内置 shell 命令。 (提示:$ man bash
。)这是暂时的。要使其永久化,请将该行添加到相关的 shell 初始化脚本中;有关详细信息,请参阅
man bash
。路径是您希望 JVM 搜索的目录和 JAR 文件的路径名列表,以便找到运行应用程序所需的类。您需要自己弄清楚这一点……或者(重新)阅读您尝试运行的任何内容的文档。
You set the Java classpath on Ubuntu the same way as you do on any Linux / UNIX platform (or indeed on Windows ... modulo some minor syntactic differences). There are two ways:
or
where
<classpath>
is a sequence of pathnames with ':' separators.For more details refer to the manual entry for the 'java' command; e.g. here and here.
If you don't understand
export CLASSPATH=...
read the Ubuntu manual entry forbash
, paying attention to what it says about setting variables, environment variables, and theexport
built-in shell command. (Hint:$ man bash
.)This is temporary. To make it permanent, add the line to the relevant shell init script; see
man bash
for details.The classpath is a list of pathnames of directories and JAR files that you want the JVM to search in order to find the classes it needs to run your application. You'll need to figure that out yourself ... or (re-)read the documentation of whatever it is you are trying to run.
如果你想从桌面运行java程序,你有三种选择。
最简单的选择是编写一个小的 shell 脚本并将其放在桌面上。最小的例子可能是:
接下来使用“jarjar”或“shade”来制作一个包含所有依赖项的大罐子,然后使用 java -jar 运行它。 (作为一个子选项,如果它真的适合您,您可以使用 META-INF/MANIFEST.MF 制作一个 jar,其中包含具有绝对路径名的类路径。)
更复杂的选择是学习使用 JNLP 构建一个可启动的项目。
If you want to run a java program from the desktop, you have three choices.
The easy choice is to write a small shell script and put that on the desktop. The smallest example might be:
Next comes the use of 'jarjar' or 'shade' to make one big jar containing all your dependencies, and then run that with java -jar. (As a sub-option, if it's really just for you, you can make a jar with a META-INF/MANIFEST.MF containing a class path with absolute pathnames.)
The more complex choice is to learn to use JNLP to build a launchable item.
IIRC 您可以使用环境变量或 java 的命令行选项来控制类路径。
IIRC you can control the classpath with either an environment variable or a command-line option to java.