Monday, December 29, 2008

Opening multiple NetBeans IDE instances simultaneously

Main concepts in this post:
  • --userdir NetBeans command line switch
  • opening multiple instances of NetBeans IDE
  • Netbeans about dialog box

This post answers questions like:
  • How to open two NetBeans IDE simulteneously?
  • What is NetBeans user directory?
  • What is the --userdir NetBeans command line switch?
  • How to know the current user directory of NetBeans?
  • How to use same NetBeans installation to open two instances?

Many a times we need to look two projects at the same time in NetBeans IDE.  If both the projects are open in two seperate NetBeans IDEs that will be easier to look into one IDE instance having one project and code into the other instance of the IDE for the other project.


The NetBeans IDE maintains one user directory for one instance.  The trick is to make seperate user directories and make shortcuts of NetBeans IDE to start the instances in those seperate user directories.  Through these shortcuts we can pass the instruction to the IDE about what user directory to choose while running the instance.

Let us take an example.  We will create two directories

1. D:\nbuserdir1 

and

2. D:\nbuserdir2

Now we will create two shortcuts on the desktop which can be done by copying the NetBeans shortcut in the start menu and making two copies with dufferent names.  Now we will right click on the shortcuts and will choose the properties.  Then we will change the execution path and add the additional part to that command as




<netbeanscommand> --userdir D:\nbuserdir1 for the first shortcut 

and

<netbeanscommand> --userdir D:\nbuserdir2 for the second shortcut.


Now we are ready to execute the NetBeans IDE in two instances.  When we double click on those instances we will have two seperate IDEs running simulteneously.

To check which user directory is currently used by the running IDE we can open the Help > About diablog box.  This dialog box will also show us the user directory used by the running instance.
 


with regards
Tushar Joshi, Nagpur

Tuesday, December 16, 2008

Annoyed about NetBeans IDE

Danny Nieuwegein from Netherlands is annoyed about NetBeans IDE and the most annoying thing in NetBeans IDE as he mentions, in his blog is, CTRL-F4 closing not only the code windows, but also the project window! and when he cleans up his screen by holding CTRL-F4, all the windows including project windows gets closed and then he need to track down the option to turn the project window back on!

I tried what he is saying and indeed the CTRL+F4 keyboard shortcut closes one window at a time in NetBeans IDE and ultimately you get just the main window.

I think Danny wants a way to close only the editor windows.  I tried to find out how to do that by right clicking an editor window.


I go the keyboard shortcut for closing all the editor windows as CTRL + SHIFT + W and it worked.  So now atleast this cannot be a reason to get annoyed with NetBeans IDE and we can use this keyboard shortcut to close just the editor windows.

With Regards
Tushar Joshi, Nagpur

Wednesday, December 10, 2008

Adding MIT license in Java Class as Header

For our open source project jcompare we are using MIT license.  According to the open source tradition we wanted the MIT license to be included in our source code files.  NetBeans makes the inclusion of license piece of cake through the templates feature.

We will use the Tools Menu and Templates option


In the various categories we have to select the Licenses Node.  We need MIT license to be listed there.  Initially there are only two entries under the Licenses node.  NetBeans CDDL and Default License.  The best way to create another license is select existing license and press the Duplicate button.

Let us press the duplicate button and we get a new License entry.  Important thing to note here is the license name shall be exactly as license-MIT.txt  

This will ensure we can use the default Java Class template as it is.   Now we will select that entry license-MIT.txt and press the Open in folder button to open this file.  We will have to change this file with our MIT license text which we will get from OSI site.



<#if licenseFirst??>
${licenseFirst}

${licensePrefix}Copyright (c)
${licensePrefix}
${licensePrefix}Permission is hereby granted, free of charge, to any person obtaining a copy
${licensePrefix}of this software and associated documentation files (the "Software"), to deal
${licensePrefix}in the Software without restriction, including without limitation the rights
${licensePrefix}to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
${licensePrefix}copies of the Software, and to permit persons to whom the Software is
${licensePrefix}furnished to do so, subject to the following conditions:
${licensePrefix}
${licensePrefix}The above copyright notice and this permission notice shall be included in
${licensePrefix}all copies or substantial portions of the Software.
${licensePrefix}
${licensePrefix}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
${licensePrefix}IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
${licensePrefix}FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
${licensePrefix}AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
${licensePrefix}LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
${licensePrefix}OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
${licensePrefix}THE SOFTWARE.
<#if licenseLast??>
${licenseLast}


Next step we will follow is to open the project.properties file.  We will navigate to the Files panel and expand the nbproject folder to see this file and double click on it to open it in editor.


We will add a new property in this file at the end.
That property will be

project.license=MIT



Now when we create a new class in our project the license text will be included as required.


The license file gets created in the config\Templates folder of the NetBeans user directory as shown in the image below:

with regards
Tushar Joshi, Nagpur

References:
UPDATE: NetBeans License Templates - John Yeary - John has more templates for licenses

Real @author name in java classes

When we create a new class in NetBeans the class is created using the default template for a Java class and this template uses the user name which is created as the computer user.  In my case it is tusharj.  This makes the class use my name as


@author tusharj



which is not exciting.  I want to use my real name and my email address after the @author java doc tag.

NetBeans provides a way to specify your own name to be used here.  Open the Tools Menu and choose the Templates option.

In the long list of Templates locate the User Configuration Properties Node and select its child node User.properties


Uncomment the #user line and add your name and email address.  Check the name I have written for me in the image below.


Now when we create a new Java class 


We can see the @author tag with my real name 

with regards
Tushar Joshi, Nagpur