Saturday, October 2, 2010

Inspiring...

Stay hungry Stay foolish...

Cool Speech...

Searching for a Java Class file locatioin in bunch of jars (JAR Scanner)

A Cool open source software I found on internet it can search a .class file from a bunch of .jar files. Download
jarscan.jar from below link...

Usage:



  • To display the help message type:
      java -jar jarscan.jar -help OR java -jar jarscan.jar





  • To find the class ArrayList starting from the root of your c: drive type:
      java -jar jarscan.jar -dir c:\ -class ArrayList


  • Here is the URL,

    http://www.inetfeedback.com/jarscan/

    A picture speaks a thousand words

    Thursday, June 18, 2009

    create and share a folder with .bat file

    Simple .bat file to create a folder and share that folder with full permission and give access to Everyone. Just put below four lines of code into any textpad save a .bat file.


    Md E:\MyFolder
    Net Share MyShare=E:\MyFolder
    Cacls E:\MyFolder /e /r Everyone
    Cacls E:\MyFolder /e /g Everyone:C

    Monday, May 4, 2009

    HOWTO:Setting up a Subversion Server on Windows Server 2003

    Recently we have migrated our repository from Serena PVCS to SVN. Here the configuration details I used to configure Subversion(SVN) on windows 2003 server.
    SVN (Tigris.org) got pretty cool exe file (Svn1ClickSetup-1.3.3.exe) which will include all it's necessary software's in a single bundle namely the software's are Subversion, SVNService and Tortoise SVN client. We just need to keep on clicking next and verify the installation location by defualt it points to C:\Pr0gram Files\subversion.

    Things To Do:
    1. Download the latest version of Svn1ClickSetup-1.3.3.exe from http://svn1clicksetup.tigris.org/.

    2. Double click on Svn1ClickSetup-1.3.3.exe and it initialize installation process just keep looking at installation window and keep hitting on next button all the way out to finish set up process.

    3. Svn1ClickSetup-1.3.3.exe will install Subversion command line tool in C:\Program File\Subversion\ and say Next now subversion will automatically pickup Editor which is Notepad.exe leave it as it is if you want you can change it to text pad or Edit plus what ever you like and say Next now it is going to create Repository (Here is the place all your work gonna save) by default it points to C:\svnrepos (if you want to change you can change it, I changed it and I created like E:\svn_repository) and say Next (this is a bit important stuff here we are going to deal with Authentication) now it points a window asking user name and password this is nothing but your admin credentials I have given as admin/sirish and say Next now it will prompts window asking project name give anything you like or your project name (testproject) and say Next now it is going install SVN client called TortoiseSVN (TSVN) and say Next this will install TSVN and it prompts a window asking Restart your system to complete installation. Just choose Restart and say Ok this will restart your System.
    Now you are pretty much done with SVN configuration on just mouse clicks see how easy it is :-) Now we see how to check-in and check-out a project to SVN using TSVN Client.

    Just give right click on desktop you see the TSVN options as mouse short cuts something like,



    Now open SVN Repo-Browser for this choose SVN Repo-browser option on mouse right click and it will ask for URL of the repository provide URL like below, http://localhost/ or http://127.0.0.1/



    Subversion will open project(s) window something like below where you see the project you created while installing(testproject) (I changed it to FirstProject)



    All the folders under FirstProject are empty. FirstProject will have 3 sub folders called branches, tags, trunk. generally trunk will hold development version of the code so go ahead and drag and drop your project folder inside this trunk or you can add the project by right-click and Add Folder option but drag and drop is cool thing to do.

    Once you drag and drop your project folder it will open up a pop up window asking enter log message so enter something you like (always write clear message saying what you gonna check-in)



    So you are done with check-in project into Subversion. Let's go and check-out the same project.
    create a folder on desktop with same name of the project (just for consistency) and then check out the project. Right click on the folder you just created and select Check-out.



    Then subversion open up a window showing Repository URL and check-out location just make sure they are right ones and say ok.



    It will download project into local directory. Then try to modify some files and check them back to repository.

    Configuring Users (Access Rights on SVN)

    Now we need to edit multiple files to configure Users, User Rights and to provide restriction to SVN at group level by creating user groups something like Developers, Testers.

    To do so by default SVN got it's won user configuration file. So open E:\svn_repository\conf directory under we find 3 files namely,
    1. authz
    2. passwd
    3. svnserve.conf
    Edit svnserve.conf and do the following changes.
    1. uncomment password-db = passwd so SVN will pickup users from passwd file.
    2. uncomment anon-access and update anon-access = none.
    3. uncomment auth-access and update auth-access = write.
    Now edit passwd file and add user name and passwords something like below,

    [users]
    admin=India@123
    sirishg=sirishg
    david=david

    Now we added 3 users for SVN and we need to create groups and provide access on project level. Some people will access some projects only. If user is not assigned to any project he can't able to access the project.

    Now edit authz and create a group and provide access at project level.

    [groups]
    development_group = sirishg,david
    admin_group=admin

    I have created two groups called development_group and admin_group and I assigned users to the groups. Remember all the users added in the groups should be declared in passwd file.

    Now providing access to all the users to just see the repository. The following wild card entry will make every user can be able to see all the project but he/she can't be able to access the project unless he/she assigned to that project.

    [/]
    * = r

    [/testproject/]
    @development_group = rw
    @admin_group = ''"

    About command means for testproject development_group have read and write access and admin_group don't have any rights. The same way you can provide access to other projects too.

    authz Conf Files look like,

    [/]
    * = r

    [/testproject/]
    @development_group = rw
    @admin_group = ''"

    passwd Conf Files look like,

    [users]
    admin=India@123
    sirishg=sirishg
    david=david

    svnserve.conf Files look like,

    [general]
    anon-access=none
    auth-access=write
    password-db=passwd

    So now you can try accessing your repository from repobrowser Now SVN will prompt you user name and password.

    Monday, October 27, 2008

    Applets are not running on Internet Explorer 7.0

    I think there was an issue with applets on Internet Explorer 7.0. When I tried to run some applets on my windows 2003 server (SP2) box with IE 7.0 and JDK 1.5 version I could not able to load applets on my browser. I tried in almost all known ways by enabling applets through browser setting Tools -->Advanced and from java console (control panel --> java console --> Advanced) but no luck finally I thought to uninstall the java and reinstall it again and did the same but still no luck so finally I have installed lower version of Internet Explorer version 6.0 and it started working...
    I think IE 7.0 has some issues still. But IE 7.0 has got some pros and cons as per my limited usage experience...

    Pros:
    • Rich look and feel
    • Tabbed browsing
    • Implemented Add-on concept as Mozilla Firefox had.
    Cons:
    • Though you enable Add-ons still browser through you message that you have not enabled add-on facility which really frustrates.
    • As I told Applet issue.
    • When we say Add-on user will easily sense that MicroSoft is trying to follow Mozilla's style of providing add-on's.
    Fix for this issue

    It started working by doing this way uninstall IE 7.0 and JDK 1.5 and then start reinstalling IE 7.0 and then install JDK 1.5. This will solve applet issue.

    Thursday, August 14, 2008

    Error Reporting through E-Mail using Log4j (SMTPAppender Class)

    This could be one of the cool thing if you get an intimation through an email when ever your application is facing the problem in production or test environments apart from this you get log file as well so we can decrees the turn around time some what in fixing and issue and making your environment up. A few months back I have implemented the same thing for one of our production application and I have used log4j for logging and emailing the log file when ever log file get populated with error level messages.
    In log4j api we have one class called SMTPAppender which will email us our log file when ever log file is populated with error level message. Just needs to configure log4j properties file with all SMTP server details.

    Note: Make sure that you should have mail.jar and activation.jar files in your class path.

    log4j.properties:

    log4j.rootLogger=INFO, filer ,SMTPTest
    log4j.appender.filer=org.apache.log4j.RollingFileAppender
    log4j.appender.filer.layout=org.apache.log4j.PatternLayout
    log4j.appender.filer.layout.ConversionPattern=%d{MMM dd HH:mm:ss} %-5p [%t] %c{2} - %m%n
    log4j.appender.filer.File=C:\\COMSProduction.log
    log4j.appender.filer.MaxFileSize=1000KB
    log4j.appender.filer.MaxBackupIndex=4

    #####################
    #SMTP appender properties#
    #####################

    log4j.appender.SMTPTest=org.apache.log4j.net.SMTPAppender
    log4j.appender.SMTPTest.Threshold=Error
    log4j.appender.SMTPTest.BufferSize=512
    log4j.appender.SMTPTest.layout=org.apache.log4j.PatternLayout
    log4j.appender.SMTPTest.layout.ConversionPattern=%d %-4r [%t] %-5p (%c:%L)%x - %m%n
    log4j.appender.SMTPTest.SMTPHost= smpt.youcompany.com
    log4j.appender.SMTPTest.To= me@who.com
    log4j.appender.SMTPTest.From= me@who.com,user@who.com
    log4j.appender.SMTPTest.Subject=COMSProductionLog - <>

    EmailSender.java - Load properties and configure SMTP properties with log4j.
    ------------------

    import org.apache.log4j.Category;
    import org.apache.log4j.PatternLayout;
    import org.apache.log4j.PropertyConfigurator;
    import org.apache.log4j.net.SMTPAppender;

    import java.io.InputStream;
    import java.util.Properties;

    /**
    * Created by IntelliJ IDEA.
    * User: sirishg
    * Date: Apr 5, 2007
    * Time: 4:38:45 PM
    * To change this template use File | Settings | File Templates.
    */

    /**
    * This class is responsible to email your application log file to SupportEngineers/Developers when ever application is caught with errors.
    * I am using SMPTAppender(from apache log4j) to do this job.
    */

    public class EmailSender {
    public static Category log = org.apache.log4j.Category.getInstance(EmailSender.class.getName());

    public static void postEmail() {

    Properties properties = null;
    try {
    properties = new Properties();
    InputStream inStream = LogManager.class.getResourceAsStream("log4j.properties");
    properties.load(inStream);

    log.info("Trying to load log4j.properties file!!");
    PropertyConfigurator.configure(properties);
    log.info("Successfuly loaded the property file!!");
    } catch (Exception e) {
    log.error("OOPS...log4j.property file has not loaded!!");
    e.printStackTrace();
    }

    /**
    * Call SMTPAppender and set all required fields to that. you can set directly from here or you can load parameters from you log4j.properties.
    * I prefer to load from log4j.properties hence you will get the chance to change perameters dynamically with out recomiling your code.
    */
    try {
    log.info("Invoking the SMTPAppender class");
    SMTPAppender emailAppender = new SMTPAppender();
    if (properties != null) {
    emailAppender.setSMTPHost(properties.getProperty("log4j.appender.SMTPTest.SMTPHost"));
    emailAppender.setFrom(properties.getProperty("log4j.appender.SMTPTest.From"));
    emailAppender.setTo(properties.getProperty("log4j.appender.SMTPTest.To"));
    emailAppender.setSubject(properties.getProperty("log4j.appender.SMTPTest.Subject"));
    }
    emailAppender.setLayout(new PatternLayout());
    emailAppender.activateOptions();
    log.addAppender(emailAppender);
    } catch (Exception e) {
    log.error("got an error in SMTPAppender, the errors are::" + e.getStackTrace());
    e.printStackTrace();
    }
    }
    }

    PostEmailTest.java
    -- Small test and try to do some mistake and put an error entry into log file now see you will get an email with your log file.
    public class PostEmailTest {
    public static void main(String[] args) throws Exception {
    LogManager manager = new LogManager();
    Logger log = manager.getLogger(PostEmailTest.class);
    String str = "Sirish";
    if (str.equals("SIRISH")) {
    log.info("both strings are equal....");
    } else {
    log.error("Strings are not equal....!");
    /**
    * Finally we rached to what we are looking for. now we got one error entry into log file and this is the time to email log file to
    * SupporEngineer so invoke EmailSender class and send .log file.
    */
    EmailSender.postEmail();
    }
    }
    }

    Tuesday, August 5, 2008

    Why Managers Fail

    Good one...
    http://managementcraft.typepad.com/management_craft/2008/06/why-managers-fa.html

    JUnit testing tips

    As we used to write our JUnit test cases for all Story cards we develop, well we follow TDD (Test Driven Development). Here are the rules we follow for our JUnit testcase as part of our TDD...
    • Never break others test case.
    • Don't update any database values as part of your JUnit testing. (But we can read DB values if required.)
    • Test your business logic no need to test java or other API's as they are well tested.
    • Try to avoid Mock Objects usage. (I think some times this mock objects will cause problems when you debug your test case - I am not quite sure to give any instance but I think so)
    • And he used to tell one more thing Clean first before committing something back to repository.
    • Ensure your JUnit test is passing on cruise control. Some time JUnit will pass locally when it actually running along with Cruise Control test beds it fails so need to ensure till you get positive build results other wise need to fix again.