Linux Mint: Modify JAVA HOME for All Users

Categories: Linux; Tagged with: ; @ April 27th, 2014 12:14

Solution A:  Modify /usr/bin/java link

# which java
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.12) (7u25-2.3.12-4ubuntu3)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
# ls -ld /usr/bin/java
lrwxrwxrwx 1 root root 22 Apr 16 21:47 /usr/bin/java -> /etc/alternatives/java
# rm /usr/bin/java
# ln -s /guoliangDev/tools/sun-jdk/jdk1.7.0_55/bin/java /usr/bin/java
# java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

Solution B: Modify /etc/profile

#vi /etc/profile


export JAVA_HOME=/guoliangDev/tools/sun-jdk/jdk1.7.0_55
export PATH=$JAVA_HOME/bin:$PATH

save the file, and

source /etc/proflie

JRE/JDE related ANT build Errors

Categories: Java; Tagged with: ; @ July 30th, 2012 18:35

I’m trying to build some java project in my new pc, got some error:

build.xml:46: Unable to find a javac compiler; is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to “C:\Program Files (x86)\Java\jre7”

or :

cannot access java.util.ArrayList
    [javac] bad class file: C:\Program Files (x86)\Java\jre7\lib\rt.jar(java/util/ArrayList.class)
    [javac] class file has wrong version 51.0, should be 49.0
    [javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
    [javac] import java.util.ArrayList;
    [javac]                  ^
    [javac] 1 error
    [javac] 100 warnings

I have config the Path environment variable, and the JRE installed in Eclipse preferences, I got those Errors also, and I forget there also need to config the ant run configuration:  run as… and switch to ‘JRE’ tab, select the right JDK.

Singleton In JDK: java.lang.Runtime

Categories: Java; Tagged with: ; @ July 3rd, 2012 23:21

Some times we need write some Singleton class for some reasons, like we need a singleton to store application settings. btw, we need this singleton thread safe.

Here is a good example for open JDK:

 * Every Java application has a single instance of class
 * Runtime that allows the application to interface with
 * the environment in which the application is running. The current
 * runtime can be obtained from the getRuntime method.

* An application cannot create its own instance of this class. * * @author unascribed * @see java.lang.Runtime#getRuntime() * @since JDK1.0 */ public class Runtime { private static Runtime currentRuntime = new Runtime(); /** * Returns the runtime object associated with the current Java application. * Most of the methods of class Runtime are instance * methods and must be invoked with respect to the current runtime object. * * @return the Runtime object associated with the current * Java application. */ public static Runtime getRuntime() { return currentRuntime; } /** Don't let anyone else instantiate this class */ private Runtime() {}

The private static runtime instance will initialized when the class loaded by JVM, so thread safe is guaranteed by JVM class load mechanism.

Eclipse is running in a JRE, but a JDK is required 解决方法

Categories: Java; Tagged with: ; @ October 7th, 2010 9:08


Eclipse is running in a JRE, but a JDK is required
Some Maven plugins may not work when importing projects or updating source folders.


1. 检查Eclipse正在使用的JRE

‘Window’ -> ‘Preferences’ -> ‘Java’ -> ‘Installed JREs’ 确定正在使用JDK而非JRE.

如果没有JDK, 则先新增一个Standard VM.

2. 配置Eclipse.ini

检查Eclipse配置文件, 增加/编辑以下代码:



1. 第一行参数名称, 第二行为值, 不能写到同一行中

2. 关于第二行的值, 因为不允许出现空格, 所以使用Progra~1或2 替代”Program Files (x86)”.
如果在Program Files下, 请使用Progra~1, 如果在x86下, 则使用Progra~2

3. 在文件中的位置, 不能放到最后(不能在-vmargs之后), 不放心的直接放到文件最前, 如:


3. 重启Eclipse, 警告不再出现.



Categories: Java; Tagged with: ; @ March 27th, 2010 15:23



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.