在 Ubuntu 上设置 Java 环境路径时遇到问题(libjvm.so:无法打开共享对象文件:没有这样的文件或目录)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18326412/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:31:58  来源:igfitidea点击:

Trouble in Setting Java Environment Path on Ubuntu (libjvm.so: cannot open shared object file: No such file or directory)

javalinuxubuntuenvironment-variablesjava-home

提问by online.0227

Found the solution!

找到了解决办法!

Ubuntu by default ignore the command "RD_LIBRARY_PATH" therefore I need to add those codes in ".bashrc" instead of "/etc/environment" or .profile.

Ubuntu 默认忽略命令“RD_LIBRARY_PATH”,因此我需要在“.bashrc”而不是“/etc/environment”或.profile中添加这些代码。

it now work perfectly fine!

它现在工作得很好!



I am trying to run a program that reads Java method from C/C++ code. (I made it on Windows successfully, now, I am working on Linux)

我正在尝试运行一个从 C/C++ 代码读取 Java 方法的程序。(我在 Windows 上成功完成,现在,我在 Linux 上工作)

I made it successfully compiled and run on Ubuntu, however, the problem is.. Whenever I try to run the program, I have to type following commands on terminal..

我使它成功编译并在 Ubuntu 上运行,但是,问题是.. 每当我尝试运行该程序时,我必须在终端上键入以下命令..

source /etc/environment
./invoke #program name is invoke

If I do not type "source /etc/environment" every time I boot my PC, the error message I get is...

如果我每次启动 PC 时都没有输入“source /etc/environment”,我得到的错误消息是...

error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory

Ok. Here is what I added in /etc/environment

好的。这是我在 /etc/environment 中添加的内容

export PATH="$PATH:/usr/lib/jvm/jdk1.7.0_25_x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x64
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server

What I want is that, as you know, I want to run the program without typing "source /etc/environment". I also tried typing those PATHs on /etc/profile, but result was same... I should type "source /etc/profile" every time I reboot my PC..

我想要的是,如您所知,我想在不键入“source /etc/environment”的情况下运行该程序。我也尝试在 /etc/profile 上输入这些路径,但结果是一样的......每次我重新启动我的电脑时我都应该输入“source /etc/profile”。

How to make it permanently applied to whole range of System without typing "source /etc/environment" stuffs everytime I boot?

如何使其永久应用于整个系统范围而无需在每次启动时输入“源/等/环境”内容?

if you need to see source code of the program, here is downloadable address: http://cfile237.uf.daum.net/attach/247819495212DF1C07B9EB

如需查看程序源码,可下载地址:http: //cfile237.uf.daum.net/attach/247819495212DF1C07B9EB

采纳答案by online.0227

Found the solution!

找到了解决办法!

Ubuntu by default ignore the command "RD_LIBRARY_PATH" therefore I need to add those codes in ".bashrc" instead of "/etc/environment" or .profile.

Ubuntu 默认忽略命令“RD_LIBRARY_PATH”,因此我需要在“.bashrc”而不是“/etc/environment”或.profile中添加这些代码。

it now work perfectly fine!

它现在工作得很好!

回答by Xabster

Put "-Djava.library.path=FULL_PATH_HERE/jre/lib/amd64" as a JVM option in your C code.

将“-Djava.library.path=FULL_PATH_HERE/jre/lib/amd64”作为C 代码中的JVM 选项。

Edit the full_path_here part.

编辑 full_path_here 部分。

The path is allowed to be relative, but I don't think you can use $JAVA_HOME as a placeholder for the environment variable.

允许路径是相对的,但我认为您不能使用 $JAVA_HOME 作为环境变量的占位符。

回答by LeandreM

I had the same problem of setting the path(permanently) however I was using Red Hat, If you look change PATH permanently on Ubuntuit might help you. There was a file on Red Hat .profilethat once you add your exports statements, they will get loaded when the computer starts. :) There should be the kind of file for ubuntu

我在设置路径(永久)时遇到了同样的问题,但是我使用的是 Red Hat,如果您在 Ubuntu 上永久更改 PATH可能会对您有所帮助。Red Hat .profile上有一个文件,一旦您添加了导出语句,它们就会在计算机启动时加载。:) 应该有 ubuntu 的那种文件

export     PATH="$PATH:/usr/lib/jvm/jdk1.7.0_25_x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x64

导出 JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x64

回答by snovelli

This worked for me:

这对我有用:

For x86:

对于 x86:

export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/i386:/usr/lib/jvm/default-java/jre/lib/i386/server

For x86_64

对于 x86_64

export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/amd64:/usr/lib/jvm/default-java/jre/lib/amd64/server

回答by Rajamohan

  1. add the path of the missing libraries in the file /etc/ld.so.conf
  2. execute the following command: ldconfig this way, you'll add the new libraries to the default ones.
  3. To check whether the new libraries have been linked, execute the following command: ldconfig -p to have the list of libraries currently linked by default.
  1. 在文件 /etc/ld.so.conf 中添加缺失库的路径
  2. 执行以下命令: ldconfig 这样,您就会将新库添加到默认库中。
  3. 要检查新库是否已链接,请执行以下命令:ldconfig -p 以默认情况下获得当前链接的库列表。