简体   繁体   English

在Linux中永久设置类路径

[英]Set classpath permanently in Linux

I am using centos and I have 4 to 5 jar files which I want to add permanently in classpath, So that I can run my program from anywhere. 我正在使用centos,我有4到5个jar文件,我想在classpath中永久添加它们,以便可以在任何地方运行程序。 I tried this- 我尝试了这个

 export CLASSPATH="/path/to/file:/path/to/file2"

Above command worked perfectly but I think it was not adding files permanently. 上面的命令运行完美,但我认为它不是永久添加文件。 When I opened new tab and tried to compile my program then I was getting same error ie jar files were missing. 当我打开新标签页并尝试编译程序时,我遇到了同样的错误,即缺少jar文件。

Now, Please help me to add these jar files permanently to classpath. 现在,请帮助我将这些jar文件永久添加到classpath。

You could add that export statement to the end of your bash init file ~/.bashrc , therefore it will in effect all the time. 您可以将该export语句添加到bash初始化文件~/.bashrc的末尾,因此它将一直有效。

By the way, a better setting of CLASSPATH would be 顺便说一句, CLASSPATH的更好设置是

export CLASSPATH="/path/to/file":"/path/to/file2":"${CLASSPATH}"

this will also preserve the initial value of that environment variable. 这也将保留该环境变量的初始值。

将路径添加到/ etc / profile,然后重新启动以生效

export CLASSPATH="/path/to/file:/path/to/file2"

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

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