在Ubuntu20上配置OpenGrok

OpenGrok是一个强大的源代码阅读器。本文介绍如何在Ubuntu20桌面上安装并配置OpenGrok.

01 - 安装tomcat9

sudo apt install -y tomcat9

 

02 - 安装universal ctags

sudo apt install -y autoconf automake                                 
                                                                                 
git clone https://github.com/universal-ctags/ctags.git                
cd ctags                                                              
./autogen.sh                                                          
./configure                                                           
make                                                                  
sudo make install

注意:Exuberant ctags已经不再被维护了,所以从源代码安装universal ctags。

 

03 - 安装OpenGrok

cd /tmp                                                                  
wget https://github.com/oracle/opengrok/releases/download/1.4.7/opengrok-1.4.7.tar.gz
sudo mkdir /opt/opengrok sudo mkdir /opt/opengrok/{src,data,dist,etc,log} sudo tar -C /opt/opengrok/dist --strip-components=1 -xzf /tmp/opengrok-1.4.7.tar.gz sudo cp /opt/opengrok/dist/doc/logging.properties /opt/opengrok/etc cd /opt/opengrok/dist/tools sudo apt install -y python3-pip sudo pip3 install opengrok-tools.tar.gz

 

04 - 配置OpenGrok运行环境

#
# 01 - Copy opengrok's source.war to tomecat9
#
sudo cp /opt/opengrok/dist/lib/source.war /var/lib/tomcat9/webapps/source.war 

#    
# 02 - Update tomcat9's web.xml
#
sudo cp /var/lib/tomcat9/webapps/source/WEB-INF/web.xml /tmp/web.xml   
sudo vi /var/lib/tomcat9/webapps/source/WEB-INF/web.xml                
  #                                                                      
  # ...Edit L13...                                                       
  #13    <param-value>/var/opengrok/etc/configuration.xml</param-value> 
  # ...Replace /var with /opt                                            
  #
                                                                     
sudo diff /var/lib/tomcat9/webapps/source/WEB-INF/web.xml /tmp/web.xml 
13c13
<         <param-value>/opt/opengrok/etc/configuration.xml</param-value>
---
>         <param-value>/var/opengrok/etc/configuration.xml</param-value>

 

05 - 使用OpenGrok

cd /opt/opengrok/src                                                            
sudo git clone https://github.com/githubtraining/hellogitworld.git 
sudo java \                                                                     
     -Djava.util.logging.config.file=/opt/opengrok/etc/logging.properties \  
     -jar /opt/opengrok/dist/lib/opengrok.jar \                                 
     -c /usr/local/bin/ctags \                                                  
     -s /opt/opengrok/src \                                                     
     -d /opt/opengrok/data -H -P -S -G \                                        
     -W /opt/opengrok/etc/configuration.xml \                                   
     -U http://localhost:8080/source 

注意待阅读的源代码对应的目录必须保存到/opt/opengrok/src下面。

通过OpenGrok生成的源代码网页效果图如下, Have fun:-)

参考资料

posted @ 2020-10-11 11:10  veli  阅读(1981)  评论(0编辑  收藏  举报