deepin2015java环境变量问题
Tofloor
poster avatar
tenlee2012
deepin
2016-01-17 08:30
Author
自己下载的java压缩包,解压自己添加的环境变量,在~/.profile和/etc/profile都添加了一模一样的,可是通过source之后,只在当前起效,重新开一个终端,又是找不到java命令,注销,重启都无效,到底是怎么回事啊
Reply Favorite View the author
All Replies
avatar
zhang12345shun
deepin
2016-01-17 09:04
#1
没必要配置JAVA_HOME
通过 update-alternatives 设置命令链接符即可
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java 1000
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_66/bin/javac 1000
Reply View the author
avatar
zhang12345shun
deepin
2016-01-17 09:41
#2
参考官网:
Starting with version 8u40, the JDK installation is integrated with the alternatives framework and after installation, the alternatives framework is updated to reflect the binaries from the recently installed JDK. Java commands such as java, javac, javadoc, and javap can be invoked from the command line.
Reply View the author
avatar
tenlee2012
deepin
2016-01-17 20:52
#3
我想知道为什么??是系统原因还是我操作原因导致没有成功?
Reply View the author
avatar
Feng Yu
deepin
2016-01-17 21:08
#4
本帖最后由 abcfy2 于 2016-1-17 13:13 编辑
https://bbs.deepin.org/post/36222
没必要配置JAVA_HOME
通过 update-alternatives 设置命令链接符即可
sudo update-alternatives --install  ...

JAVA_HOME变量有时候是需要的。因为基于JAVA开发的很多程序是通过JAVA_HOME变量来决定JDK/JRE路径的。
比如tomcat, gradle, groovy等等……
意味着当系统有多个JDK版本的时候可以通过修改JAVA_HOME变量来让这些程序使用不同的JDK/JRE启动。

但对于自己写的JAVA程序来说,一点用处都没(当然你也可以指定使用$JAVA_HOME/bin/java启动你的JAVA程序)

update-alternatives的作用是在/usr/bin/下创建一个软连接,由于/usr/bin/本来就在PATH下,所以无需手工修改PATH而已。
所以开源社区还有个更好的方案自动使用$PATH第一个命中的java/javac路径来确定JDK路径:

  1. export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
Copy the Code


上面这段代码的意思是通过readlink -f追踪/usr/bin/java最终的绝对路径,然后通过sed替换删掉最后的bin/java,得到了JRE的绝对路径。

当然有很多改进空间,如/usr/bin/java换成$(which java),意味着你可以从自己的PATH变量中选出第一个被命中的JAVA。也可以把java换成javac,意味着你得到的将是JDK的路径,而非JRE
Reply View the author
avatar
Feng Yu
deepin
2016-01-17 21:08
#5
https://bbs.deepin.org/post/36222
我想知道为什么??是系统原因还是我操作原因导致没有成功?

你怎么配置的?把你的配置贴出来
Reply View the author
avatar
zhang12345shun
deepin
2016-01-17 21:17
#6
https://bbs.deepin.org/post/36222
JAVA_HOME变量有时候是需要的。因为基于JAVA开发的很多程序是通过JAVA_HOME变量来决定JDK/JRE路径的。
比 ...

谢谢。明白更多了。
Reply View the author
avatar
rookie5566
deepin
2016-01-17 22:46
#7
我也是这个问题,到了到现在也没个解决方法,source就当前窗口生效,新开或者重启后都失效,只能设置在~/.bashrc文件中,但是启动应用的时候得从终端启动,目前只发现deepin有这种问题出现 。
似乎论坛也没见官方的人来解决。
Reply View the author
avatar
ArthurDeepin
deepin
2016-01-17 22:55
#8
看到还是有人没搞好?
要不试一下写到 ~/.xprofile 里看看,没有就新建一个
Reply View the author
avatar
tenlee2012
deepin
2016-01-18 08:20
#9
本帖最后由 tenlee2012 于 2016-1-18 00:28 编辑
https://bbs.deepin.org/post/36222
你怎么配置的?把你的配置贴出来
  1. #set jdk environment
  2. export Test="mytest"
  3. export JAVA_HOME="/usr/lib/java/jdk1.8.0_20"
  4. export CLASSPATH=".:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH"
  5. export PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH"
Copy the Code


所有的我自己设置的环境变量都是只在当前终端下source有效,到底是什么问题啊,深度2015的bug吗????
Reply View the author
avatar
tenlee2012
deepin
2016-01-18 08:28
#10
管理员啊,急啊。。。。。。。
Reply View the author
avatar
tenlee2012
deepin
2016-01-18 08:29
#11
https://bbs.deepin.org/post/36222
看到还是有人没搞好?
要不试一下写到 ~/.xprofile 里看看,没有就新建一个 ...

不行,试了
Reply View the author
avatar
cxbii
deepin
2016-01-18 23:12
#12
https://bbs.deepin.org/post/36222
管理员啊,急啊。。。。。。。

https://bbs.deepin.org/post/36259
这个呢
Reply View the author
avatar
tenlee2012
deepin
2016-01-21 03:46
#13
本帖最后由 tenlee2012 于 2016-1-21 21:07 编辑

asdfafasfadsfadfasdfadsfadsf
Reply View the author