Friday, December 28, 2012

Setup yum repository from a linux iso shared on remote windows machine

1. Mount remote windows share on linux system

In general, a useful stuff – specially when important software-installers are stored on a windows share. It can be useful to mount the windows share on your linux system to use it efficiently.

Following are the steps:
  • Login to Linux as root user
  • > mkdir /mtn/winshare 
  • > mount -t cifs //<windows-machine-IP-addr>/<folder-path/ -o username=<user>,password=<pw> /mnt/winshare (For RHEL > 4)
  • > mount -t smbfs //<windows-machine-IP-addr>/<folder-path/ -o username=<user>,password=<pw> /mnt/winshare (For RHEL < 4)

2. Extract Files from iso image and create yum repository

  • > mkdir -p /mnt/iso/{1,2,3}
  • > mount -o loop /mnt/winshare/disk.iso /mnt/iso/1
  • > rpm -ivh  /mnt/iso/1/Packages/<createrepo-package-name>.rpm
  • > cd /mnt/iso
  • > createrepo .
  • > yum clean all

3. Create yum repository configuration file

  • > vi /etc/yum.repos.d/iso.repo
  • Place following text in iso.repo
           [iso] 
           name=My ISO Repo
           baseurl=file:///mnt/iso
           enabled=1
           gpgcheck=0 

Now you should be able to install any package from iso using yum.

- Sarang Anajwala

Monday, December 24, 2012

Debug class-not-found exception

Print ClassNotFoundException

A simple problem that I have found many people struggling with – how to print class-path. Following is the line that can be used to print classpath.

Arrays.toString((((URLClassLoader) Test.class.getClassLoader().getURLs()));

This code returns an array list of all jars and directories on the classpath of the classloader.

-          Sarang Anajwala

 

Friday, December 14, 2012

End of Public Updates for Java SE 6

A quick update on future of Java 6.

From oracle blog -
“The last publicly available release of Oracle JDK 6 is to be released in February, 2013. This means that after 19 February 2013, all new security updates, patches and fixes for Java SE 6 and Java SE 5 will only be available through My Oracle Support and will thus require a commercial license with Oracle.“


Presents a case for upgrade to Java 7!

- Sarang Anajwala

Tuesday, December 11, 2012

Log4j 2.0 - Some important features


Log4j’s latest 2.0 version has been recently released. Following are few of the important and very useful features of Log4j-2.0:

1.       Supports parameter substitution (same as slf4j)
For example:
   LOGGER.info (“User Id is { } and User Email is { }”, userId, userEmail);

2.       Flow Tracing:
To print the entry and exit of a method.
Example:
  public String getUserEmail(int userId) {
    logger.entry(userId);
    User user = UserDao.getUser(userId)
    String email = user.getEmail();
    return logger.exit(email);
  }
  This method will log following messages:
    19:08:07.061 TRACE com.class.MyClass 10 getUserEmail -  entry parms(1)
    19:08:07.061 TRACE com.class.MyClass 13 getUserEmail -  exit with (User.Email@gmail.com)
 
3.       Markers:
To log some special messages.
For example:
 public class MyApp {
 
   private Logger logger = LogManager.getLogger(MyApp.class.getName());
   private static final Marker QUERY_MARKER = MarkerManager.getMarker("SQL");
               
   public String doQuery(String table) {
     logger.entry(param);
     logger.debug(QUERY_MARKER, "SELECT * FROM {}", table);
     return logger.exit();
   }
} 
 
4.       Messages:
Very useful to standardize the format of an application’s log messages.
Example:
            logger.info("User {} has logged in using id {}", username, userId);        
      The above log message can be standardized by implementing a class ‘LoggedInMessage’ implementing ‘Message’ interface.
            logger.info(new LoggedInMessage(userName, userId)); 
                    (‘getFormattedMessage’ method of ‘Message’ interface is used to log the message string.)
        
Some more important types of messages are ThreadDumpMessage, TimestampMessage, MapMessage and few more.
 
5.       Plug-ins:
Log4j 2 uses a Plugin system that makes it extremely easy to extend the framework by adding new Appenders, Filters, Layouts, Lookups, and Pattern Converters without requiring any changes to Log4j.           


-          Sarang Anajwala