How to run VisualVM in Ubuntu

Running VisualVM in Ubuntu.
I am new hand in Linux OS. So I hope my experience can help people in similar conditions.
First, of course, you need to install Java Development Kit (JDK) into your ubuntu since it is not defauly installed.

 
Second, it is time to install VisualVM.
VisualVM is free and open source software. If you install Sun-JDK, it is already binded. If you installed open-JDK like me, you need to download and install it independently.

sudo apt-cache search visualvm
(# now make sure you can download VisualVM from your software repository)
(# if there is not any visualVM in your current repository, you need to search internect to learn how to add new repository)

sudo apt-get install visualvm
(# Then visualVM will be installed to default path. In my machine, it is "usr/lib/visualVM")


After installation, the main code and resources of VisualVM can be found in default installation path (in my PC, it is “usr/lib/visualVM”), and the short cut start file (“jvisualvm”) will be created in “usr/lib”.
Third, before you directly run VisualVM, you MUST edit the auto-generated script file “jvisualvm” to match the java environment.
I hate using VI in Linux because I cannot remember hotkeys. So I installed leafpad (a simple notepad software) to edit txt files.


apt-cache search 'notepad*'
(# here I found 'leafpad' available in my repository, so I installed it)

sudo apt-get install leafpad


The default content of script file MUST be changed, unless you cannot launch VisualVM successfully.
There is a section of code (as follows) in the file. (maybe starts from line 12). It means that the system checks all given paths (from [path1] to [path n]), if any path includes file “javac” in sub-folder “[path]/bin”, then VisualVM will use this path as “jdkhome”.


jdkhome=
for j in [path1] [path2] ... [path n]; do
if [-x $j/bin/javac ]; then
   jdkhome=$j
   break;
fi
done

So here lies the problem. 
WHEN YOU INSTALL VISUALVM, the content of this script file will not be updated according to your own JAVA ENVIRONMENT.
so I changed the this section of code as follows to solve the problem (by inserting my JDK path into condition part):

jdkhome=
for j in /usr/lib/jvm/openJDK-1.7 [path 1] [path 2] ... [path n]; do
if [-x $j/bin/javac ]; then
   jdkhome=$j
   break;
fi
done

DO NOT FORGET TO SAVE THE FILE!
DO NOT FORGET TO REOPEN THE FILE TO CHECK YOUR CHANGE!
Now, you can successfully invoke VisualVM.
Enjoy monitoring!

你可能感兴趣的:(java,TO,性能,ubuntu,in,visualvm,run,英文,how,外语)