Matt Clark

How to enable keywords in Eclipse and Subversion (SVN)

March 26th, 2009

I’ve used CVS (Concurrent Versions System) for years, and really like the keyword substitution feature.  It’s not hard to grok – when a file is committed to CVS, it is first scanned for words that should be replaced.  Specifically, if a text file contains the following:
//  File name: $HeadURL$
//  Revision: $Revison$
//  Last modified: $Date$
//  Last modified by: $Author$
//
//  description of the following file...

Then after it is checked in with keyword substitution, it looks like this:

//  File name: best-practices.php
//  Revision: 1.1
//  Last modified: 2009-02-26 22:27
//  Last modified by: mclark
//
//  description of the following file...

Even better, I usually just use the single line version of “$Id$” that puts all the important information into a single line.

//  $Id: best-practices.php 1619 2009-02-26 22:27 mclark $
//
//  description of the following file...

However keyword substitution is not activated by default from within Eclipse and its SVN module titled Subclipse.  Eclipse is the best IDE (Integrated Development Environment) that I’ve ever used (but it won’t be explained here).  These are the steps to activate the svn-keyword-substitution feature in Eclipse:

  1. Install Subclipse into your Eclipse application (you’ve probably already done this if you’re reading this post!)
  2. Right-mouse-click on your project folder, and choose Team => Set Property from the popup menu
  3. Enter the property name:  svn:keywords
  4. Enter the text property:  Author Date Id Revision HeadURL
  5. Click the  Set property recursively checkbox
  6. OK

Now keywords are substituted when you commit a file in SVN, just like they were in CVS.  Also, you can shorten Revision to Rev and HeadURL to URL.

Tags: , ,

worked in academia, corporate research labs and several technology startup companies prior to GORGES. His expertise is software architecture, database development, and system administration. Matt brings GORGES over 25 years experience developing fast and robust software on a multitude of platforms and languages.

13 Responses to “How to enable keywords in Eclipse and Subversion (SVN)”

  1. Michel says:

    Is it possible to add this also for new files? I don’t want to do this for every new file…

  2. Matt Clark says:

    Yes, if you follow these directions then it will work for ALL existing and new files. Note that the setting was applied at the topmost level in the project hierarchy.

  3. Edwin Dhondt says:

    Is there a means to state that the properties should only be set on *.java files, because I don’t want to use these keywords on other files.

    I don’t think it is possible using set property because it doesn’t allow me to specify a file pattern.
    It also doesn’t seem to work when adding *.java = … auto-prop to subversion config file.
    Any advice ?
    Thanks,
    EDH

  4. Matt Clark says:

    The answer is YES this can be applied just to *.java files. I see in the latest Eclipse that the menu item is now “Change ASCII/Binary Property”, and the first line says “Filter files by name”. I entered *.java, and only the java source files were listed.

    Did I misunderstand your question, or does this help?

  5. EDH says:

    Where do you exactly see this option ? In which menu ?
    Thanks, EDH

  6. Marcel says:

    Thanks, this was very helpful.

  7. Quonn's Blog says:

    Enable keywords substitution using Eclipse and Subversion (SVN)…

    To enable keywords substitution as I usually have with the CVS, you just need to enable a svn properties on the Eclipse project configuration. These are the steps to activate the svn-keyword-substitution feature in Eclipse: Install …

  8. Mikalai says:

    Thank you !!! It helped me.

  9. Alex says:

    Hi,
    how can I disable this in eclipse?
    There’s no “remove property’ afaics.
    Thanks

  10. Matt Clark says:

    @Alex: I don’t know how to remove the property. However if you learn how, please post here to teach the rest of us!

  11. Edgar says:

    Matt,

    I followed your instructions here and applied them on eclipse under a directory structure. When I open a file i.e. a pom.xml I don’t see a description anywhere on the file as to who the Author is, Date, ID etc.

    Thanks.

  12. Robert says:

    Matt
    Thanks, this worked for me with Eclipse 3.6 and Subclipse 1.8.
    I now have a comment in my java file showing, for example

    * $LastChangedRevision: 905 $
    * $LastChangedDate: 2012-04-24 14:14:33 -0500 (Tue, 24 Apr 2012) $

    What I want though is to be able to use this as a string to generate a version number of the software package. Any suggestions?

  13. Robert says:

    Matt,

    ignore this. It was trivial
    set a Java parameter
    public static final String SVN_REV= “$LastChangedRevision: $”;
    and after each commit it gets updated

Leave a Reply

©2012 GORGES - All rights reserved
where programming meets design and lives happily ever after