Tags opengrok By crazygit On 2012-12-14




以opengrok用户身份登录安装jdk和Exuberant Ctags.

$ sudo apt-get install sun-java6-jdk ctags


$ cd /var/local/
$ tar -zxvf /path/to/opengrok-0.11.1.tar.gz
$ tar -zxvf /path/to/apachetomcat-7.0.6.tar.gz


$ mkdir -p ~/opengrok/projects/project1
$ mkdir -p ~/opnegrok/projects/project2
$ cd ~/opengrok/projects/project1
$ download code of project1 (such as: git clone ... or repo init ... && repo sync)
$ cd ~/opengrok/projects/project2
$ download code of project2 (such as: git clone ... or repo init ... && repo sync)




$ /var/local/apache-tomcat-7.0.6/bin/

访问http://检查tomcat 是否正常工作



$ sudo OPENGROK_TOMCAT_BASE=/var/local/apache-tomcat-7.0.6 /var/local/opengrok-0.11.1/bin/OpenGrok deploy

这一步实际操作是/var/local/opengrok-0.11.1/lib/source.war部署到/var/local/apache-tomcat-7.0.6/webapps/ 访问 已经可以看到opengrok页面了,但是没有项目的数据信息。 在/var/local/apache-tomcat-7.0.6/webapps/目录下面可以看到一个source目录和source.war,就是刚刚部属的产物。 source.war已经没有什么用了,可以删除。


创建索引时,会创建三个目录,一个data目录来存放索引信息,一个etc目录创建配置信息和一个log目录。 如想让~/opengrok/来存放索引,则指定OPENGROK_INSTANCE_BASE=~/opengrok, 则指定OPENGROK_INSTANCE_BASE=~/opengrok

$ OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=~/opengrok/ ./OpenGrok index ~/opengrok/projects/

这一步命令的执行时间视~/opengrok/projects/的代码数量决定。 最后会在~/opengrok 目录下面看到data,etc,log 三个目录

访问http://,enjoy it!


首先更新项目代码或者下载新的项目到~/opengrok/projects目录下面。 然后重新执行

$ OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=~/opengrok/ ./OpenGrok index ~/opengrok/projects/



可以通过修改/var/local/apache-tomcat-7.0.6/webapps/source/index_body.html来定制化你的OpenGrok首页。 如添加公司LOGO或一些有用的帮助信息。



$ OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=~/opengrok/ ./OpenGrok index ~/opengrok/projects/

其实调用的是opengrok lib目录下的jar包:

java -Xmx2048m -Dorg.opensolaris.opengrok.history.cvs=/usr/bin/cvs
-jar /data/opengrok/opengrok-0.11.1/bin/../lib/opengrok.jar
-P -S -r on -v -c /usr/bin/ctags-exuberant -a on
-W /data/opengrok/opengrok_data/etc/configuration.xml
-U localhost:2424 -s /data/opengrok/projects/
-d /data/opengrok/opengrok_data/data -H..


$ java -jar opengrok.jar

Usage: opengrok.jar [options]

-A ext:analyzer
    Files with the named extension should be analyzed with the specified class

-a on/off
    Allow or disallow leading wildcards in a search

-B url
    Base URL of the user Information provider. Default: ""

    Print per project percentage progress information(I/O extensive, since one read through dir structure is made before indexing, needs -v, otherwise it just goes to the log)

-c /path/to/ctags
    Path to Exuberant Ctags from by default takes the Exuberant Ctags in PATH.

    Store history cache in a database (needs the JDBC driver in the classpath, typically derbyclient.jar or derby.jar)

-d /path/to/data/root
    The directory where OpenGrok stores the generated data

    Economical - consumes less disk space. It does not generate hyper text cross reference files offline, but will do so on demand - which could be sightly slow.

    Generate history cache for all repositories

-h /path/to/repository
    just generate history cache for the specified repos (absolute path from source root)

-I pattern
    Only files matching this pattern will be examined (supports wildcards, example: -I *.java -I *.c)

-i pattern
    Ignore the named files or directories (supports wildcards, example: -i *.so -i *.dll)

-j class
    Name of the JDBC driver class used by the history cache. Can use one of the shorthands "client" (org.apache.derby.jdbc.ClientDriver) or "embedded" (org.apache.derby.jdbc.EmbeddedDriver). Default: "client"

-k /path/to/repository
    Kill the history cache for the given repository and exit. Use '*' to delete the cache for all repositories.

    List all repository pathes and exit.

-L path
    Path to the subdirectory in the web-application containing the requested stylesheet. The following factory-defaults exist: "default", "offwhite" and "polished"

-l on/off
    Turn on/off locking of the Lucene database during index generation

-m number
    The maximum words to index in a file

-N /path/to/symlink
    Allow this symlink to be followed. Option may be repeated.

    Do not generate indexes, but process all other command line options

-O on/off
    Turn on/off the optimization of the index database as part of the indexing step

    Generate a project for each of the top-level directories in source root

-p /path/to/default/project
    This is the path to the project that should be selected by default in the web application(when no other project set either in cookie or in parameter). You should strip off the source root.

-Q on/off
    Turn on/off quick context scan. By default only the first 32k of a file is scanned, and a '[..all..]' link is inserted if the file is bigger. Activating this may slow the server down (Note: this is setting only affects the web application)

    Run as quietly as possible

-R /path/to/configuration
    Read configuration from the specified file

-r on/off
    Turn on/off support for remote SCM systems

    Search for "external" source repositories and add them

-s /path/to/source/root
    The root directory of the source tree

-T number
    The number of threads to use for index generation. By default the number of threads will be set to the number of available CPUs

-t number
    Default tabsize to use (number of spaces per tab character)

-U host:port
    Send the current configuration to the specified address (This is most likely the web-app configured with ConfigAddress)

-u url
    URL to the database that contains the history cache. Default: If -j specifies "embedded", "jdbc:derby:$DATA_ROOT/cachedb;create=true"; otherwise, "jdbc:derby://localhost/cachedb;create=true"

    Print version and quit

    Print progress information as we go along

-W /path/to/configuration
    Write the current configuration to the specified file (so that the web application can use the same configuration

-w webapp-context
    Context of webapp. Default is /source. If you specify a different name, make sure to rename source.war to that name.

-X url:suffix
    URL Suffix for the user Information provider. Default: ""

-z number
    depth of scanning for repositories in directory structure relative to source root

PS:默认情况下,调用OpenGork脚本是会生成项目的历史记录的,如果不想生成脚本的历史记录, 可以修改 OpenGrok脚本的UpdateGeneratedData 方法,去掉StdInvocation -H-H