BuildDeploy.bat

 cscript /nologo c:\Utils\stopjboss.vbs

 set JBOSS_DEPLOYMENT=c:\jboss\standalone\deployments
 set DEVELOPMENT_HOME=c:\projectName
 set BRANCH=BranchName\ReleaseNo
 
 del /q %JBOSS_DEPLOYMENT%\*.*
 cd %DEVELOPMENT_HOME%\%BRANCH%
 
 call mvn clean
 call mvn install -o
 
 IF EXISTS  %DEVELOPMENT_HOME%\%BRANCH%\SpringMVC.war (
  goto :startServer
 ) else (
  echo Build Failed
 )

 exit /b

:startServer
 copy %DEVELOPMENT_HOME%\%BRANCH%\SpringMVC.war %JBOSS_DEPLOYMENT%
 cscript /nologo c:\Utils\startjboss.vbs
goto :eof

startjboss.vbs

 Set WshShell = WScript.CreateObject("WScript.Shell")
 activateServer("Server")
 WshShell.SendKeys "%{d}"

 Function activateServer(windowName)
   WshShell.SendKeys "^{3}"
   WScript.Sleep 500
   WshShell.SendKeys windowName
   WScript.Sleep 500
   WshShell.SendKeys "{ENTER}"
 End Function

stopjboss.vbs

 Set WshShell = WScript.CreateObject("WScript.Shell")
 activateServer("Server")
 WshShell.SendKeys "%{s}"
 WScript.Sleep 5000

How it Works

  • We are using a VBScript to Start and Stop server by Sending Key Strokes to Eclipse(Shortcut Keys)
  • The mvn clean and mvn install is done in 2 different steps to make sure that clean of the war files happen before the new file is created since executing clean and install in single shot happened to give inconsistent results
  • Once the build is done we are checking whether the war file is created or we are assuming the build failed and we are not starting the server
  • The builddeploy.bat should be configured in External Tools Configuration
  • Workdirectory is the one which has pom.xml of the project
  • Assign a shortcut key to Run Last Run Build Configuration

How to arrange Two excel sheets side by Side

Steps

  • Click on View tab, Click on New Window
  • Click on Arrange All, Select Vertical

Now to compare 2 Rows in 2 Excel Sheets

  • Select the Rows in the Sheet which needs to be compared
  • Click on Conditional Formatting Option
  • =ISNA(MATCH(A2,Sheet2!A2,FALSE))

If you want the formatting to be applied only for one Column select that column and apply conditional formatting

Instead of

 =$A$2:$B$7

it should be

 =$A$2:$A$7

in Conditional Rules Formatting Manager

Download Excel

How to highlight rows which have different row value of one Column

null

The Steps are as Below
Below is the way to highlight the rows based on a change in value in the single column.The Column considered is SNo

Steps

  • Select the whole DataSet LookUpArray on which the conditional formatting to be applied
  • Click on Conditional Formatting
  • Click on new Rule
  • Use a formula to determine which cells to format
  • Note : The formula used is relative formula =ISNA(MATCH($D2,$A$2:$A$7,FALSE))
  • Use the format option to apply the Conditional format on the cells
  • The same could be seen in Conditional Formatting->Manage Rules for future rule edits

In the below image Rows 4 and 7 are highlighted because of mismatch in SNo and 5 is highlighted because of mismatch in fruit name

Checking for Identical rows in two tables with more than one column

 =ISNA(MATCH($D2,$A$2:$A$7,FALSE)&MATCH($E2,$B$2:$B$7,FALSE) )

Steps

  • First we are checking if the rows in D2 is same as on in A2 to A7
  • Second we are checking if the rows in E2 is same as on in B2 to B7
=MATCH(lookup_value, lookup_array, match_type)

lookup_value – Value you are interested in
lookup_array – Column you want to look for value
match_type – Whether it should be a exact match or approximate match

Match Function

 =MATCH(D2,A2:A7,FALSE)

Looks for D2 in the Lookup Array in A2 to A7

Match with Msg

  =IFERROR(MATCH(D2,A2:A7,FALSE),"Missing")

In case of Error IFERROR is used to make it display as Missing

Match with ISNA

  =ISNA(MATCH(D2,A2:A7,FALSE))

If #N/A then it would be displayed as True

Match with 2 Columns

  =MATCH(D2,A2:A7,FALSE)&MATCH(E2,B2:B7,FALSE)

In the above code, we are checking the two columns for uniqueness by using two match function
and using && Operator to display the value as 11 or #N/A

System Path is one which comes when you type cmd in windows->run
Other simple commands are dir,ver,cls

Storing Variable Name

>>set strName=Mugil
>>echo  %strName%

Typing set and pressing enter will return system variable

>>set

To check for List of Users type

>>set USER

String Cancatenation

>>set strFirstName=Mugil
>>set strFirstName=%strFirstName% Vannan

Displays Volumne Info

>>vol D:
>>dir /B

Get option of Util
>>dir /?
>>cls /?

Lists folder in Dir with details

>>dir

Lists folder in Dir without details

>>dir /B

Turn off the command executed in Screen

>>echo off

Turn off the Display of Batch Statements when Echo off command activated(Works for Script)

>>@echo off

/A tag will allow us to work with mathematical operation

>>Set /A

/P tag will allow user inputs by prompting msg

>>Set /P

Getting Inputs from Console

@echo off

set /p name=Please Enter your name

echo.
echo Your name is - %name%

pause

Labels(Organize code pieces)

:label

Goto(Jumps to Label and starts execution)

goto :label

Comments

rem this is comment
:: this is again a comment

Functions

:getSum
   echo The Sum is Addition of Two Numbers
goto :eof	 

Calling Functions within function

:getMath
	echo Calling Sum Function
	call :getSum	
goto :eof

:getSum
   echo The Sum is Addition of Two Numbers
goto :eof	 

Functions that takes Argument


The below batch script helps to read the selected trailing lines from Log File

@echo off
cls
setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" C:\Users\Mugil\Desktop\test.txt | find /C ":""

for /f %%a in ('!cmd!') do set totalLines=%%a
rem echo "totalLines-"%totalLines%


@set linesToConsider=4
set /a lineToStart="%totalLines%-%linesToConsider%" 

rem echo "lineToStart-"%lineToStart%

set content=
for /f "skip=%lineToStart% delims=" %%i in ('type C:\Users\Mugil\Desktop\test.txt') do set content=!content! %%i


@echo "content - "%content%


If NOT "%content%"=="%content:SUCCESS=%" (
    echo Build Successful
) else (
    echo Build Failed
)

pause

Working with EntityManagerFactory – Best Practices

  1. EntityManagerFactory instances are heavyweight objects. Each factory might maintain a metadata cache, object state cache, EntityManager pool, connection pool, and more. If your application no longer needs an EntityManagerFactory, you should close it to free these resources.
  2. When an EntityManagerFactory closes, all EntityManagers from that factory, and by extension all entities managed by those EntityManagers, become invalid.
  3. It is much better to keep a factory open for a long period of time than to repeatedly create and close new factories. Thus, most applications will never close the factory, or only close it when the application is exiting.
  4. Only applications that require multiple factories with different configurations have an obvious reason to create and close multiple EntityManagerFactory instances.
  5. Only one EntityManagerFactory is permitted to be created for each deployed persistence unit configuration. Any number of EntityManager instances may be created from a given factory.
  6. More than one entity manager factory instance may be available simultaneously in the JVM. Methods of the EntityManagerFactory interface are threadsafe.
Posted in JPA.

Java Archives (JAR) A JAR file encapsulates one or more Java classes, a manifest, and a descriptor. JAR files are the lowest level of archive. JAR files are used in J2EE for packaging EJBs and client-side Java Applications.

A WAR (Web Archive) is a module that gets loaded into a Web container of a Java Application Server. A Java Application Server has two containers (runtime environments) – one is a Web container and the other is a EJB container.

The Web container hosts Web applications based on JSP or the Servlets API – designed specifically for web request handling – so more of a request/response style of distributed computing. A Web container requires the Web module to be packaged as a WAR file – that is a special JAR file with a web.xml file in the WEB-INF folder.

An EJB container hosts Enterprise java beans based on the EJB API designed to provide extended business functionality such as declarative transactions, declarative method level security and multiprotocol support – so more of a RPC style of distributed computing. EJB containers require EJB modules to be packaged as JAR files – these have a ejb-jar.xml file in the META-INF folder.

Enterprise applications may consist of one or more modules that can either be Web modules (packaged as a WAR file) or EJB modules (packaged as a JAR file) or both of them. Enterprise applications are packaged as EAR files – these are special JAR files containing an application.xml file in the META-INF folder.

Basically EAR files are a superset containing WAR files and JAR files. Java Application Servers allow deployment of standalone web modules in a WAR file, though internally they create EAR files as a wrapper around WAR files. Standalone web containers such as Tomcat and Jetty do not support EAR files – these are not full fledged Application servers. Web applications in these containers are to be deployed as WAR files only.

In application servers – EAR files contain configurations such as application security role mapping, EJB reference mapping and context root url mapping of web modules.

Apart from Web modules and EJB modules EAR files can also contain connector modules packaged as RAR files and Client modules packaged as JAR files.