James Selvakumar’s Blog

April 7, 2008

Subversion and NetBeans - A quick start guide

Filed under: java, netbeans, version control — James Selvakumar @ 10:24 am
Tags: ,

Introduction:

Subversion is arguably the most popular version control system as of now. No wonder NetBeans has very good support for Subversion. I personally feel that a java developer must be familiar with both these tools. This article shall help you to get started with both these tools.

Objectives:

- To create a simple java project in NetBeans.

- To import the java project into the subversion repository.

- To commit the changes made in a java source file.

- To view the revision history of a java source file which was changed.

- To rollback to the previous revision of the java source file.

Requirements:

- NetBeans 6.1 Beta or NetBeans 6.0

- Subversion

- TortoiseSVN

- Though not mandatory, but a basic knowledge of subversion concepts.

Note: You can read this article to learn how to install/configure Subversion and TortoiseSVN.

Step 1:

Create a new “Java Application” project called “SimpleLogin”.

Step 2:

Create a new JFrame called “LoginFrame” under the package “org.example.simplelogin” and add the necessary components as shown below.

Step 3:

Name the swing components accordingly.

Your application should like this now on preview:

Step 4:

Create a java class named “LoginService” under the package “org.example.simplelogin”.

Step 5:

Add the following code to the LoginService class.

Here we are defining a simple method which shall return true if the username is “guest” and the password is “password”.

Step 6:

Now open “LoginFrame.java” and add the following methods.

The above methods are self explanatory. We are just doing a simple validation and calling the login method we defined previously in the class LoginService.

Step 7:

Now double click the login “button” in the design mode of LoginFrame.java to create the event handling method named “loginButtonActionPerformed”. Add the following code to call the “performLogin” method.

That’s it.

Step 8:

Run the project.

If you enter the username as “guest” and password as “password”, you will get an output like this.

Otherwise, you will be getting an output like this.

Ok, our simple login application is ready for prime time :-). Now let us import this project into a subversion repository.

Step 9:

Create an empty folder called “MyRepository” in a preferred location.

Step 10:

Create a subversion repository in the empty “MyRepository” folder as mentioned below, by right clicking anywhere inside the windows explorer.

Accept the default option (FSFS) in the “Create Repository” window.

That’s it. Your repository should be ready when you press “OK” and it should look something like this.

Step 11:

Let us import the NetBeans project we have created into the subversion repository. Right click the NetBeans project we have created and then click “Versioning -> Import into Subversion Repository”.

NetBeans will prompt you with a window. Enter the path of your repository as shown below.

Click the “Next” button and enter the “Repository Folder” name into which you would like to import your project. To make things simple, let us enter our NetBeans project name itself as the “Repository Folder” name. Also enter a small description about this import activity as shown below.

We are almost there. Click the “Next” button and the IDE will show a window like this.

Accept the default entries and click “Finish”. Congratulations! you have imported your project successfully into the subversion repository.

Right click anywhere in your desktop/windows explorer and click “TortoiseSVN -> Repo-Browser” and then enter the path of your subversion repository. You can see all your project files sitting comfortably inside the subversion repository. :-)

Step 12:

Let us play around with some more cool subversion integration features offered by NetBeans. Open the class “LoginService.java” and change the value of “DUMMY_PASSWORD” from “password” to “guest”.

You can see the IDE markup a blue shade near the line you made the change. This indicates that your source file has got something different than the version in the repository. You can also note that the IDE change your java source file name’s font-color to blue.

Let us turn our focus to the editor window again. Click the blue stripe shown by the IDE near the  place where you made changes to the source file. The IDE will popup a small hint-window.

screenshot

You can see the previous value of the DUMMY_PASSWORD there. The IDE also provides you a set of buttons to revert back the changes or to have a “diff” view on the changes made. Let us explore the “diff’ functionality of the IDE first by clicking the “diff” button.

screenshot

The IDE will display the “diff” view of the “working copy” and the “HEAD” revision (the latest committed version) in the repository.

screenshot

From the above figure, you can see the current and previous value of the string DUMMY_PASSWORD. Now you can revert back to the old value of “DUMMY_PASSWORD” by clicking the replace  button (displayed like an arrow)

screenshot

When you press the “replace” button, the IDE will replace the “current” value with the “original” value.

screenshot

The “diff” view provided by the IDE will be very useful to examine and compare the changes made to the “working copy”  alongwith the option to revert back to the original version in the repository. But if all you need is to quickly revert back some change to the original version in the repository, you can click on the blue strip in the source code and click the “revert” button.

screenshot

That’s cool, right?

Step 13:

Enough playing. Now let us commit the changes we made in our source file. Ensure that the source file you are willing to commit is in focus and click the menu “Versioning -> Commit”

screenshot

When you click the “Commit” menu item, the IDE will prompt you with a window to enter the “message” for this commit operation. Enter a commit message and click the “Commit” button.

screenshot

Step 14:

Let us explore the history of our source file and see the the changes we made all along. Click the “Versioning -> Search History” menu.

screenshot

The IDE will display all the versions of the source file.

screenshot

In the “Search History” window, the IDE offers two views, “summary” view and “diff” view. By default, the IDE displays the “summary” view. The “diff” view contains more information.

screenshot

You can straightaway “revert” or “rollback” to previous revisions just by right clicking a particular revision.

screenshot

Nice, isn’t it? There are still a lot more cool subversion features offered by NetBeans. I will blog more about that later. I hope the information provided here was useful to you.

Love NetBeans? Blog about it and submit your blog to the NetBeans Blogging Contest.

11 Comments »

  1. I finally decided to write a comment on your blog. I just wanted to say good job. I really enjoy reading your posts.

    Tina Russell

    Comment by Tina Russell — April 7, 2008 @ 10:31 am

  2. [...] Vladimir Sizikov wrote an interesting post today onHere’s a quick excerptIntroduction:. Subversion is arguably the most popular version control system as of now. No wonder NetBeans has very good support for Subversion. I personally feel that a java developer must be familiar with both these tools. … [...]

    Pingback by Subversion and NetBeans - A quick start guide | Quick Work — April 7, 2008 @ 11:46 am

  3. [...] More: Subversion and NetBeans - A quick start guide [...]

    Pingback by Subversion and NetBeans - A quick start guide — April 7, 2008 @ 1:23 pm

  4. Hi,
    My name is James Branam and I’m the NetBeans Community Docs Manager. Your blog entry would make a fantastic tutorial for our Community Docs wiki (http://wiki.netbeans.org/wiki/view/CommunityDocs). Would you be willing to contribute it? If you need any help or have any questions, please contact me at james.branam@sun.com. I look forward to hearing from you.

    Comment by James Branam — April 8, 2008 @ 7:24 am

  5. Hi James,

    This article is easy to understand and detailed. I liked the article. I am still on blogger, saw your pages look more professional in wordpress :)

    Best wishes for next post.

    with regards
    Tushar Joshi, Nagpur

    Comment by Tushar Joshi — April 16, 2008 @ 10:29 am

  6. Hi Tushar,
    Thank you very much for your comments. I too had a blog in blogger but found wordpress more suitable for me.

    Comment by James Selvakumar — April 16, 2008 @ 4:12 pm

  7. Hi James,

    Excellent blog and I love the graphics, but I need help creating the svn+ssh link on a unix build and not on Windows. I have to have the ssh rather than the apache access and it lives on a machine in the dmz so I can not use file:/// access. It is amazing how much help there is on this subject and how little actual information like yours.

    If the subversion repository lives on a machine in the dmz and I get to it through an ssh tunnel, how exactly do you you set up subversion and netbeans to talk? I have tried starting it as a stand alone server and as a command run from a tunnel and even though I can ssh into the machine where the repository lives and I can run svn on the pc in a command window, netbeans 6.1 just tells me that the svn connection was closed unexpectedly.

    I think that a blog of this quality on that side of the subject would be quite popular indeed as I can not seem to actually find one - especially using 6.1

    Any help you can be is most appreciated.

    – Jeff

    Comment by Jeff Brower — May 1, 2008 @ 4:00 am

  8. [...] Subversion and NetBeans - A quick start guide [...]

    Pingback by Entramos entre los 100 mejores blogs de Netbeans | Edisoncor’s Weblog — May 16, 2008 @ 12:37 am

  9. felicitacion por tu blog

    saludos

    Comment by edisoncor — May 16, 2008 @ 1:11 am

  10. Hi James,

    Just to let you know, I got pride I don’t just leave comments, but this…it really deserves such. You really did an Excellent job. For the first time I study a tutorial and understand every explanation without scratching my head.I really appreciate your effort, and the fact that you killed 1 bird with 1 stone, the swing part makes the graet intro too. I know a lot of people who can get going with swing using your blog. BIG UP!!!

    Good luck with the next blog.

    lcvster.

    Comment by lvcster — May 30, 2008 @ 9:38 am

  11. Hi all,
    Thank you very much for every one of you who read this blog. Special thanks for those who gave valuable comments. Your comments really motivated me hopefully enough to come out with more contributions from me.

    I would love to inform you all that this blog entry has been selected as a winner in the “Netbeans blogging contest”.

    Thank you once again. I hope you enjoyed this post.

    Comment by James Selvakumar — May 31, 2008 @ 6:15 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.