简体   繁体   English

如何在Ubuntu中设置临时Java类路径

[英]How to set a temporary Java classpath in Ubuntu

I am writing a Java program and I need to set a temporary classpath that includes my package. 我正在编写Java程序,并且需要设置一个包含我的包的临时类路径。 The package is on my Ubuntu desktop, which I am importing as /home/gaurav/Desktop. 该软件包位于我的Ubuntu桌面上,我将其导入为/ home / gaurav / Desktop。 Do you have any idea how to set the Java CLASSPATH temporarily? 您知道如何临时设置Java CLASSPATH吗?

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). 您可以在Ubuntu上以与在任何Linux / UNIX平台上相同的方式来设置Java类路径(或者在Windows上以相同的语法差异进行模设置)。 There are two ways: 有两种方法:

$ java -cp <classpath> some.ClassName arg1 arg2 ... 

or 要么

$ export CLASSPATH=<classpath>
$ java some.ClassName arg1 arg2 ... 

where <classpath> is a sequence of pathnames with ':' separators. 其中<classpath>是带有':'分隔符的一系列路径名。

For more details refer to the manual entry for the 'java' command; 有关更多详细信息,请参见“ java”命令的手册条目; eg here and here . 例如在这里这里


If you don't understand export CLASSPATH=... read the Ubuntu manual entry for bash , paying attention to what it says about setting variables, environment variables, and the export built-in shell command. 如果您不了解export CLASSPATH=...阅读Ubuntu手册中的bash ,注意它关于设置变量,环境变量和export内置shell命令的说明。 (Hint: $ man bash .) (提示: $ man bash 。)

This is temporary. 这是暂时的。 To make it permanent, add the line to the relevant shell init script; 要使其永久,请将行添加到相关的shell init脚本中; see man bash for details. 有关详细信息,请参见man bash


how do i get details for my path which path i have set 我如何获取我设置的路径的详细信息

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. classpath是您希望JVM搜索以便查找运行应用程序所需的类的目录和JAR文件的路径名的列表。 You'll need to figure that out yourself ... or (re-)read the documentation of whatever it is you are trying to run. 您需要自己弄清楚……或(重新)阅读您要运行的文件的文档。

If you want to run a java program from the desktop, you have three choices. 如果要从桌面运行Java程序,则有三个选择。

The easy choice is to write a small shell script and put that on the desktop. 简便的选择是编写一个小的Shell脚本并将其放在桌面上。 The smallest example might be: 最小的示例可能是:

#!/bin/sh
java -cp YOUR_CLASSPATH YOUR_CLASS_NAME "$*"

Next comes the use of 'jarjar' or 'shade' to make one big jar containing all your dependencies, and then run that with java -jar. 接下来是使用'jarjar'或'shade'创建一个包含所有依赖项的大jar,然后使用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.) (作为子选项,如果确实适合您,则可以使用包含绝对路径名的类路径的META-INF / MANIFEST.MF制作一个jar。)

The more complex choice is to learn to use JNLP to build a launchable item. 更为复杂的选择是学习使用JNLP来构建可启动项目。

IIRC您可以使用环境变量或Java的命令行选项来控制类路径。

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

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