工欲善其事,必先利其器之—使用OpenGrok阅读源码

工欲善其事,必先利其器之—使用OpenGrok阅读源码OpenGrok的介绍OpenGrokisafastandusablesourcecodesearchandcrossreferenceengine.Ithelpsyousearch,cross-referenceandnavigateyoursourcetree.Itunderstandsvariousprogramfilefor…

大家好,又见面了,我是你们的朋友全栈君。

OpenGrok的介绍

OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It understands various program file formats and history from many Source Code Management systems. In other words it lets you grok (profoundly understand) source code and is developed in the open, hence the name OpenGrok. It is written in Java.

OpenGrok的安装

前置环境

  • Java运行环境至少是1.8以上
  • 安装Java Web容器(classfish或tomcat8.x以上版本)
  • 安装Universal ctags

Tomcat的安装

Tomcat8的下载
把下载的压缩包解压,并放到你喜欢的某个本地目录,如解压后的目录为

/Users/luogw/dev_tool/apache-tomcat-8.5.31
注:解压的文件默认没有执行权限的,需要对该目录的所有文件加上可执行权限

drwxr-xr-x@ 25 luogw  staff     850  4 27 21:25 ./
drwxr-xr-x@ 13 luogw  staff     442  4 27 21:26 ../
-rw-r--r--@  1 luogw  staff   34985  4 27 21:24 bootstrap.jar
-rw-r--r--@  1 luogw  staff    1703  4 27 21:24 catalina-tasks.xml
-rw-r--r--@  1 luogw  staff   15900  4 27 21:24 catalina.bat
-rw-r--r--@  1 luogw  staff   23463  4 27 21:25 catalina.sh
-rw-r--r--@  1 luogw  staff  207125  4 27 21:25 commons-daemon-native.tar.gz
-rw-r--r--@  1 luogw  staff   25145  4 27 21:24 commons-daemon.jar
-rw-r--r--@  1 luogw  staff    2040  4 27 21:24 configtest.bat
-rw-r--r--@  1 luogw  staff    1922  4 27 21:25 configtest.sh
-rw-r--r--@  1 luogw  staff    8509  4 27 21:25 daemon.sh
-rw-r--r--@  1 luogw  staff    2091  4 27 21:24 digest.bat
-rw-r--r--@  1 luogw  staff    1965  4 27 21:25 digest.sh
-rw-r--r--@  1 luogw  staff    3574  4 27 21:24 setclasspath.bat
-rw-r--r--@  1 luogw  staff    3680  4 27 21:25 setclasspath.sh
-rw-r--r--@  1 luogw  staff    2020  4 27 21:24 shutdown.bat
-rw-r--r--@  1 luogw  staff    1902  4 27 21:25 shutdown.sh
-rw-r--r--@  1 luogw  staff    2022  4 27 21:24 startup.bat
-rw-r--r--@  1 luogw  staff    1904  4 27 21:25 startup.sh
-rw-r--r--@  1 luogw  staff   49336  4 27 21:24 tomcat-juli.jar
-rw-r--r--@  1 luogw  staff  405109  4 27 21:25 tomcat-native.tar.gz
-rw-r--r--@  1 luogw  staff    4574  4 27 21:24 tool-wrapper.bat
-rw-r--r--@  1 luogw  staff    5483  4 27 21:25 tool-wrapper.sh
-rw-r--r--@  1 luogw  staff    2026  4 27 21:24 version.bat
-rw-r--r--@  1 luogw  staff    1908  4 27 21:25 version.sh

添加可执行权限

luogw@luogw-MacBook-Pro dev_tool$ chmod -R +x apache-tomcat-8.5.31
# 启动Tomcat
luogw@luogw-MacBook-Pro dev_tool$ ./apache-tomcat-8.5.31/bin/startup.sh
Using CATALINA_BASE:   /Users/luogw/dev_tool/apache-tomcat-8.5.31
Using CATALINA_HOME:   /Users/luogw/dev_tool/apache-tomcat-8.5.31
Using CATALINA_TMPDIR: /Users/luogw/dev_tool/apache-tomcat-8.5.31/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
Using CLASSPATH:       /Users/luogw/dev_tool/apache-tomcat-8.5.31/bin/bootstrap.jar:/Users/luogw/dev_tool/apache-tomcat-8.5.31/bin/tomcat-juli.jar
Tomcat started.

用浏览器打开 http://localhost:8080/ ,正常情况下看到所示页面,表明安装成功
这里写图片描述
在.bash_profile中添加如下启动与并闭的Tomcat的alias

# for tomcat
alias start_tomcat='${HOME}/dev_tool/apache-tomcat-8.5.31/bin/startup.sh'
alias close_tomcat='${HOME}/dev_tool/apache-tomcat-8.5.31/bin/shutdown.sh

Universal Ctags的安装

使用brew安装Ctags

brew install --HEAD universal-ctags/universal-ctags/universal-ctags

OpenGrok的安装

OpenGrok下载列表
下载对应的压缩包并解压,解压出来的目录放在你喜欢的某个目标即可,如我的解压目录位置是 /Users/luogw/dev_tool/opengrok-1.1-rc29

OpenGrok的使用实践

示例:搭建JDK源码的阅读环境

环境配置

在.bash_profile文件中添加如下环境变量的配置

# for tomcat
alias start_tomcat='${HOME}/dev_tool/apache-tomcat-8.5.31/bin/startup.sh'
alias close_tomcat='${HOME}/dev_tool/apache-tomcat-8.5.31/bin/shutdown.sh'
# for opengrok,实际目录位置视具体的情况更改
OPENGROK_INSTANCE_BASE=${HOME}/dev_tool/opengrok-1.1-rc29
export OPENGROK_INSTANCE_BASE
OPENGROK_TOMCAT_BASE=${HOME}/dev_tool/apache-tomcat-8.5.31
export OPENGROK_TOMCAT_BASE
OPENGROK_CTAGS=/usr/local/bin/ctags
export OPENGROK_CTAGS
OPENGROK_SRC_ROOT=${HOME}/personal/code
export OPENGROK_SRC_ROOT
OPENGROK_DATA_ROOT=${HOME}/personal/opengrok_index
export OPENGROK_DATA_ROOT
OPENGROK_VERBOSE=true
export OPENGROK_VERBOSE
alias opengrok='${HOME}/dev_tool/opengrok-1.1-rc29/bin/OpenGrok'

发布Web应用

luogw@luogw-MacBook-Pro opengrok_index$ opengrok deploy
Loading the default instance configuration ...
Installing /Users/luogw/dev_tool/opengrok-1.1-rc29/bin/../lib/source.war to /Users/luogw/dev_tool/apache-tomcat-8.5.31/webapps ...
Start your application server (Tomcat),  if it is not already
running, or wait until it loads the just installed web  application.
OpenGrok should be available on <HOST>:<PORT>/source
where HOST and PORT are configured in Tomcat.

生成索引

luogw@luogw-MacBook-Pro notes$ source ~/.bash_profile
luogw@luogw-MacBook-Pro notes$ opengrok index
Loading the default instance configuration ...
WARNING: OpenGrok generated etc path /Users/luogw/dev_tool/opengrok-1.1-rc29/etc  doesn't exist Attempting to create generated etc directory ... Creating default /Users/luogw/dev_tool/opengrok-1.1-rc29/logging.properties ...

生成索引需要些时间…..

搜索代码

# 启动Tomcat
start_tomcat
# 浏览器打开链接 [http://localhost:8080/source/](http://localhost:8080/source/)

效果截图如下
这里写图片描述

这里写图片描述

参考资料

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/141722.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 堆和栈的区别(队列和栈的区别)

    堆(Heap)与栈(Stack)是开发人员必须面对的两个概念,在理解这两个概念时,需要放到具体的场景下,因为不同场景下,堆与栈代表不同的含义。一般情况下,有两层含义:(1)程序内存布局场景下,堆与栈表示的是两种程序内存分区;(2)数据结构场景下,堆与栈表示两种常用的数据结构。1.程序内存分区——堆与栈栈由操作系统自动分配释放,用于存放函数的参数值、局部变量的值等,其操作方式类…

  • 怎么获取Spring的ApplicationContext

    怎么获取Spring的ApplicationContext

    2021年12月10日
  • linux 查看当前用户密码

    linux 查看当前用户密码用过Linux系统的人都知道,Linux系统查看用户不是会Windows那样,鼠标右键看我的电脑属性,然后看计算机用户和组即可。那么Linux操作系统里查看所有用户该怎么办呢?用命令。其实用命令就能很轻松的查看到Linux系统有哪些用户。  1、Linux里查看所有用户  (1)在终端里.其实只需要查看/etc/passwd文件就行了.  (2)看第三个参数:500以上的,就是后面建的用户了.其它则为系统的用户.  或者用cat/etc/passwd|cut-f1-d:  2、用.

  • Android触摸屏事件派发机制详解与源码分析二(ViewGroup篇)「建议收藏」

    Android触摸屏事件派发机制详解与源码分析二(ViewGroup篇)「建议收藏」PS一句:最终还是选择CSDN来整理发表这几年的知识点,该文章平行迁移到CSDN。因为CSDN也支持MarkDown语法了,牛逼啊!【工匠若水http://blog.csdn.net/yanbober】该篇承接上一篇《Android触摸屏事件派发机制详解与源码分析一(View篇)》,阅读本篇之前建议先阅读。当然,阅读完这一篇之后可以阅读继续进阶的下一篇《Android触摸屏事件派发机制详解与源码分

  • CSS3+jQuery实现时钟插件

    查看效果:http://hovertree.com/texiao/hoverclock/demo4.htm本插件使用方便,可以在博客园的页面中使用,请看本页面右侧:http://www.cnblog

    2021年12月21日
  • mysql优化器不能使用hash索引来加速_数据库主键索引和唯一索引的区别

    mysql优化器不能使用hash索引来加速_数据库主键索引和唯一索引的区别1.hash表只能匹配是否相等,不能实现范围查找select * from xx where id > 23; 这时就没办法索引了2.当需要按照索引进行order by时,hash值没办法支持排序select * from xx order by score desc;如果score为建立索引的字段,hash值没办法辅助排序。3.组合索引可以支持部分索引查询,如(a,b,c)的组合索引,查询中只用到了阿和b也可以查询的,如果使用hash表,组合索引会将几个字段合并hash,没办法支持部分索引

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号