Saturday, September 22, 2018

Compile and Run Java Program From Sublime Text 3


Dear All,

Today, I am going to write about how you can compile and run your Java program from Sublime Text.

First, you need to set a Build System. To achieve it, follow below steps:
1) Goto Tools -> Build System  -> New Build System
2) A editor tab will open. Remove all predefined code and paste below code

{
    "shell_cmd": "javac $file_name && java $file_base_name",
    "working_dir": "${project_path:${folder}}",
    "selector": "source.java"
}

After pasting above code, save file with Java.sublime-build under sublime-text-3/Packages/User/.

Now, Goto Tools -> Build System and select Java (you will see new build after following above steps).

Now press Ctrl+B and enjoy the result. Please note that Ctrl+B is used to Build your program.

Enjoy coding with this lightweight software. Do comment if above post helps you.

Thanks.

Sunday, July 15, 2018

Difference Between Apache Common Logging and Log4J

Dear Folks,

Log4j is a logging framework, i.e. it provides the code to log messages while Commons-logging is an abstraction layer for logging frameworks, it doesn't log anything itself. For example if I write code using commons logging and deploy it on JBoss, the logging is done by log4j, but if I deploy it on WebSphere logging is done by WebSphere's own logging implementation. If I run the same code as a stand alone application it Java's own logging that is used.

Hope this help you in understanding the difference between two. 

Sunday, June 4, 2017

WRITE PERMISSION ON SAMBA DRIVE ON LINUX

Dear Readers,

You can find various post on installing SAMBA on Linux. In my post, I am sharing you the method through which you can allow windows users to write / copy data on your LINUX based drive.

Please remember that before that you have to create a user whom you can provide rights to copy data on Linux machine. User name should be common on Windows and LINUX.

Now, time to start real thing. Open your smb.config file (located in /etc/samba/ on LINUX drive)

[windowsSharing]
   comment = File sharing path for windows
   path = /home/user/abc/  [path which you want to share]
   writeable = yes
   browseable = yes
   public = yes
   guest ok = yes
   force user = your_user_name

Now save your file and run following command

sudo service smbd restart

After restart of service, you will be able to share your files between linux and windows.

If this post helps you then please leave a comment to increase its reliability. Also comments are welcomed to improve this post (if any).





Tuesday, July 26, 2016

Could not get lock /var/lib/dpkg/lock

Today, I tried to install Git on my Ubuntu machine and during that I received following exception related to locking. In my this post, I have shared all commands and error messages with you.


Command
sudo apt-get install git

Error Message
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?



After searching above message, I found a command

sudo lsof /var/lib/dpkg/lock

after pressing ENTER, it might asked you for password. Type the password and in result you might get following output

lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
unattende        1468 root    5uW  REG    8,1        0 154817 /var/lib/dpkg/lock

Type following command to kill the session with provided PID by your system. In my case PID # was 1468. I use following command to kill this process id.

sudo kill 1468

After execution of above statement, now I was able to download GIT by using following command again which I executed in start.

sudo apt-get install git

In case if this article helps you then please leave a comment to increase its credibility.

Thanks.

Sunday, July 24, 2016

NodeJS Series: Calling Sleep Method.

Dear Friends,

This is my first article about NodeJS, I am currently exploring it and problems which I found during my learning sessions, I will share it to you with my blog posts.

Today while writing some code, I come across the need of sleep functionality between two transactions. While doing google, I found "sleep" library which provide required functionality.

Calling of sleep method is simple e.g.,

sleep.sleep(1) // time will be defined in seconds 

But before that you need sleep library / package. To download it, use following npm command

npm install sleep

After successful installation, write following code to test this functionality.

var sleep = require('sleep');

function callLoops()
{
for(var a=1;a<10;a++)
{
console.log('%d',a);
sleep.sleep(1); //times in seconds.
}
}

callLoops();

and save this code in myExample.js file.

Execute the file with following command

node myExample.js

Congratulations...... You have achieved the goal.

That's all for now folks..... If this post help you then please increase its credibility by posting your comments.

Thanks.

Monday, March 14, 2016

HOW TO USE SPRINGFORM:ERROR TAG

To use Spring Form Error Tag, you have to follow following steps.

Your JSP Page should look like this:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>About Us Page</title>
    </head>
    <body>      
        <sf:form method="POST" action ="/SpringBasics/redirect.aspx" modelAttribute="basicClass">
            FirstName: <sf:input path="firstName" />
            <sf:errors path="firstName" />
        <br/>
            <input type="submit" value="Redirect Page" />    
        </sf:form>
    </body>
</html>


Tuesday, February 9, 2016

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'xxx' available as request attribute

While trying to use Spring MVC form Tags, I come across following exception


java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userInput' available as request attribute

Below is my JSP Code with Spring Tags

<%@page contentType="text/html" pageEncoding="UTF-8" session="false" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="st"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>
<!DOCTYPE html>
<html>
    
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>About Us Page</title>        
        <st:url var="bootstrapp_theme" value="/resources/css/bootstrap-theme.css" />
        <st:url var="bootstrapp_css" value="/resources/css/bootstrap.css" />
        <st:url var="jquery" value="/resources/js/jquery-2.2.0.js" />
        <st:url var="bootstrapp_js" value="/resources/js/bootstrap.js" />
        <link href="${bootstrapp_theme}" rel="stylesheet" />
        <link href="${bootstrapp_css}" rel="stylesheet" />        
        <script src="${jquery}" ></script>
        <script src="${bootstrapp_js}" ></script>
        
        
    <body>
        <h1 class="text-center">ABC CORPORATION</h1>
        
        <sf:form method="POST" action ="/SpringBasics/redirect">
            
            <table>
                <tr>
                
                    <td>Login ID: &nbsp;&nbsp;<input type="text" name="userName" />
                       <br> Email: &nbsp;&nbsp;<sf:input type="email" path="email" />
                       <br> My Label: &nbsp;&nbsp;<sf:label id="lbl1" path="myLabel"   />
                         
                    </td>
                </tr>
                <tr>
                    
                    <td>Password:&nbsp;&nbsp;<input type="number"  name="extension" /></td>
                </tr>
            </table>


            <input type="submit" value="Redirect Page" />
        </sf:form>
    </body>
</html>


To  resolve it I created a properties class which is defined below


package springbasics;



/**
 *
 * @author Zeeshan
 */

public class userInput {

    protected String _email;

    protected String _myLabel;

    public String getMyLabel() {
        return _myLabel;
    }

    public void setMyLabel(String _myLabel) {
        this._myLabel = _myLabel;
    }

    public String getEmail() {
        return _email;
    }

    public void setEmail(String _email) {
        this._email = _email;
    }


}

and change my JSP Code from 
        
<sf:form method="POST" action ="/SpringBasics/redirect">

To

<sf:form method="POST" action ="/SpringBasics/redirect" modelAttribute="userInput" >


Also change my controller class parameter From 

@RequestMapping(value = "/", method = GET)
    public String aboutUs() {     
        return "aboutus";      
    }

To

@RequestMapping(value = "/", method = GET)
    public String aboutUs(userInput obj) {     
        return "aboutus";      
    }


This resolve the above error message. 

If suggested solution help you in solving your issue then please comment to increase its credibility.

Thanks.


Compile and Run Java Program From Sublime Text 3

Dear All, Today, I am going to write about how you can compile and run your Java program from Sublime Text. First, you need to set a B...