如何在 Linux 中设置 Java 类路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2973624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set Java classpath in Linux?
提问by Sanjeev
I downloaded apache-log4j-1.2.16.zip
and unziped it. I then renamed it as LOG4J_HOME
and placed it in /home/appnetix
folder which is my folder. I tried setting the classpath in the terminal using the following command :
我下载apache-log4j-1.2.16.zip
并解压了它。然后我将它重命名为LOG4J_HOME
并将它放在/home/appnetix
文件夹中,这是我的文件夹。我尝试使用以下命令在终端中设置类路径:
[appnetix@Sanjeev ~]$ set classpath=%path%;LOG4J_HOME/log4j-1.2.16.jar;
That returned:
那返回:
bash: LOG4J_HOME/log4j-1.2.16.jar: Permission denied
I tried doing this:
我尝试这样做:
[appnetix@Sanjeev ~]$ set classpath=%path%;//home/appnetix/LOG4J_HOME/log4j-1.2.16.jar;
But I got this:
但我得到了这个:
bash: //home/appnetix/LOG4J_HOME/log4j-1.2.16.jar: Permission denied
Please help, I'm new in Linux (one month).
请帮忙,我是 Linux 新手(一个月)。
回答by zed_0xff
export CLASSPATH=/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar
or, if you already have some classpath set
或者,如果您已经设置了一些类路径
export CLASSPATH=$CLASSPATH:/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar
and, if also you want to include current directory
并且,如果您还想包含当前目录
export CLASSPATH=$CLASSPATH:/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar:.
回答by Peter Tillemans
You have to use ':' colon instead of ';' semicolon.
您必须使用 ':' 冒号而不是 ';' 分号。
As it stands now you try to execute the jar file which has not the execute bit set, hence the Permission denied.
就目前而言,您尝试执行未设置执行位的 jar 文件,因此权限被拒绝。
And the variable must be CLASSPATH not classpath.
并且变量必须是 CLASSPATH 而不是类路径。
回答by shyam.m
Can you provide some more details like which linux you are using? Are you loged in as root? On linux you have to run export CLASSPATH = %path%;LOG4J_HOME/og4j-1.2.16.jar If you want it permanent then you can add above lines in ~/.bashrc file.
您能否提供更多详细信息,例如您使用的是哪种 linux?您是否以 root 身份登录?在 linux 上你必须运行 export CLASSPATH = %path%;LOG4J_HOME/og4j-1.2.16.jar 如果你想要它永久,那么你可以在 ~/.bashrc 文件中添加上面的行。