Friday, 28 July 2017

Download a directory by wget in UNIX

Download entire directory from Nexus by wget command:

 wget -r -nH --cut-dirs=6 --no-parent --reject="index.html*"  --user=<USER> --ask-password  http://<host>:<port>/nexus/content/repositories/Test-Releases/com/edu/test/

For e.g.  In Nexus there is a folder test and inside that there are different folders with version number.

/test/1.0
/test/1.1

Below are arguments of wget commands.

-r  : Recursive
-nH : Ignore the hostname. If this parameter is not passed then it will create the folder with name of nexus host and port

--cut-dirs : Ignore the number of directories post Nexus host and port. If 5 is passed in this case then in local directories will be like edu/test/*

--reject="index.html*" : Download the actual content but not the index.html

--ask-password  : It will ask for password after running command

Friday, 14 July 2017

Call shell script from Java code

Below is the code to call the shell script from Java code. This will call the shell script and wait for it's execution and print the output.

public static void main(String[] args) throws Exception {
        try {
                String param1=args[0];
               
                String scriptName = "/root/script.ksh";
                String commands[] = new String[]{scriptName,param1};

                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(commands);
                proc.waitFor();
                StringBuffer output = new StringBuffer();
                BufferedReader reader = new BufferedReader(new       InputStreamReader(proc.getInputStream()));
                String line = "";                      
                while ((line = reader.readLine())!= null) {
                        output.append(line + "\n");
                }
                System.out.println("===> " + output);
        } catch (Exception e) {
                e.printStackTrace();
        }

Clone/Checkout specific file/folder from GIT

By default git checkouts the entire repository to local. As it used to compress the data during storage and checkout so it takes very less time. But if you want to checkout only one file then use below command.

git archive --remote=ssh://git@host:port/project_key/repos/repoName.git HEAD <fileName/FolderName> | tar -x

Maven command to download and deploy to Nexus from command line


This will deploy any artifacts from command line without pom.xml. Here repositoryId will be the id defined in settings.xml.

mvn deploy:deploy-file -Dfile=file_FullPath
-DgroupId=*** -DartifactId=*** -Dversion=***
-Dpackaging=jar   -Durl={repo_url} -DrepositoryId=releases


This command will download the artifacts from Nexus via command line.

mvn -C org.apache.maven.plugins:maven-dependency-plugin:2.4:get
-DremoteRepositories=http://<host:port>/nexus/content/repositories/Test/
-DgroupId=com.edu.test -DartifactId=testArtifact-Dversion=1.0 -Dpackaging=jar

rsync with compress option

This is the fastest way to copy data from one server to another.It will compress the data and transfer .

1) rsync -avxH ~/source_dir/  username@remote_host:destination_directory

This will sync data under source_dir to destination_directory

2) rsync -avxH ~/source_dir  username@remote_host:destination_directory

This will create a directory source_dir under destination_directory and copy data under source_dir


In case of local server

rsync -avxH /source /destination

Saturday, 6 August 2016

Run jar file in Unix machine

java -classpath "/devuser/test/test/bismaya/TestPOC/poc.jar:/devuser/test/test/bismaya/TestPOC/ojdbc7.jar" com.edu.test.main.Main

While creating the jar make sure you have selected Main as the class containing main method. Add all the jars to classpath by separating :.

Or

java -classpath `pwd` com.edu.test.main.Main.

In this case all the jars should be present in the current dir.

Or

java -jar jarName.jar --> provided there is no dependency jar is required.

Wednesday, 27 April 2016

Unix commads : Find command example

find . -not -path '*/\.*' -type d \( -iname "$version_id" \) ! -newermt `date +%y%m%d -d "30 days ago"` | tee -a "$log_file"



find . -not -path '*/\.*' -type d \( -iname "$version_id" \) - Find the directory not present in hidden directories

! -newermt `date +%y%m%d -d "30 days ago"`  - Older than 30 days


find . ! -newermt 2016-02-22 ! -type d -delete - Delete the older before the specified date


find . -type l -ls - Find all links


find . -not -path '*/\.*' -type d \( -iname "$version_id" \) ! -newermt `date +%y%m%d -d "63 days ago"` | xargs  rm -rf -- To delete

Upload and Download artifacts from Nexus by cmd line

Download command
-------------------------
mvn -C org.apache.maven.plugins:maven-dependency-plugin:2.4:get
-DremoteRepositories={URL of the repository}
-DgroupId={groupID} -DartifactId={artifactId} -Dversion={version} -Dpackaging=jar -DupdateReleaseInfo=true


Upload command
----------------------
mvn deploy:deploy-file -Dfile=file_FullPath
-DgroupId=*** -DartifactId=*** -Dversion=***
-Dpackaging=jar   -Durl={repo_url} -DrepositoryId={id from setting.xml}

It will download the respective maven plugins to the M2_REPO and then it will upload the artifacts specified. There should be maven installed in the machine where you are trying to upload/download.


Setting.xml
--------------

 <localRepository>C:\M2_REPO</localRepository>

<servers>
  <server>
      <id>releases</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  <server>
        <id>snapshots</id>
        <username>deployment</username>
        <password>deployment123</password>
  </server>



<mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>external:*</mirrorOf>
      <url>http://indlin714:28081/nexus</url>
    </mirror>


<profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <activation>
              <activeByDefault>true</activeByDefault>
         </activation>    
<repositories>
        <repository>
          <id>releases</id>
          <url>http://host:port/nexus/content/repositories/testRepository</url>
          <releases><enabled>true</enabled></releases>
        </repository>
     
  <repository>
         <id>snapshots</id>
          <url>http://host:port/nexus/content/repositories/isr-fnd-public</url>
          <snapshots><enabled>true</enabled></snapshots>
         </repository>

</repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>


<activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>











Thursday, 8 October 2015

Create/update Jar file in Unix without affecting the Manifest.MF

Update a jar file :  jar -uf  <jar_name>  <path_to_file/folder to be updated>.
 The <Path_To_File> should be same as the path inside the jar file .

Update jar without affecting existing Manifest : 

jar  -cmf  META\-INF/MANIFEST.MF  <Jar_File_Name>  <Files_To_Be_Packed>

Tuesday, 16 June 2015

Create Package by Maven


Create the assembly.xml and call it from pom.xml.

assembly.xml
-----------------

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>assembly</id>
  <formats>
    <format>jar</format>
  </formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>

<fileSet>
<outputDirectory>product/template-topologies</outputDirectory>
<directory>${env.HOME}/workspace/src/main/java/topologies</directory>
<includes>
<include>*.topology</include>
<include>**/*.*.topology</include>
</includes>
<fileMode>744</fileMode>
</fileSet>

 </fileSets>

 </assembly>



Main Pom.xml
------------------

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.5</version>
        <dependencies>
          <dependency>
            <groupId>your.group.id</groupId>
            <artifactId>my-assembly-descriptor</artifactId>
            <version>1.0-SNAPSHOT</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <!-- This is where we use our shared assembly descriptor -->
              <descriptorRefs>
                <descriptorRef>assembly.xml</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
      </plugin>

Monday, 15 June 2015

How to execute scripts(.ksh,.sh stc) by maven

Use Maven exec plugin to execute the script.
In <executable> you can specify the type of file.
In <workingDirectory> provide the path to the script file.
In <arguments> provide the script file name and any parameter used inside the script.

       <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                         <execution>
                            <id>createSymLinks</id>
                            <phase>install</phase>
                            <goals>
                              <goal>exec</goal>
                                                        </goals>
                            <configuration>
                                      <executable>ksh</executable>
                                      <workingDirectory>${env.HOME}/config/src
                                      </workingDirectory>
                                      <arguments>
                                                  <argument>create_links.ksh</argument>
                                                  <argument>${BUILD_VERSION}</argument>
                                       </arguments>
                            </configuration>
                         </execution>
                   </executions>
        </plugin>

Friday, 15 May 2015

Building C++ application in Maven

You have to use com.github.maven-nar plugin for building the CPP application.


If you have multiple modules in CPP application ,you can define the parent pom. Define the group-id in the module tag of the parent pom.
-----------------------------------------------------------------------------------------------------
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.amdocs.amcApiPar</groupId>
  <artifactId>amcApiPar</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>amcApiParent</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <modules>
    <module>com</module>
    <module>mro</module>
    <module>test</module>
    <module>multiThreadTest</module>
    <module>dm</module>
  </modules>
  
</project>

If you want to create .so file then you have to define the library type as shared.
------------------------------------------------------------------------------------------------

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
<parent>
 <groupId>com.amdocs.amcApiPar</groupId>
 <artifactId>amcApiPar</artifactId>
 <version>0.0.1-SNAPSHOT</version>
</parent>

    <groupId>com</groupId>
    <artifactId>com</artifactId>
    <packaging>nar</packaging>
    <version>main</version>

    <properties>
        <skipTests>true</skipTests>
<base.dir>${env.HOME}/workspace/AMC_Build</base.dir>
<srcDir>${base.dir}/${env.BUILD_VERSION}/amcapi</srcDir>
<buildDir>${base.dir}/proj</buildDir>
<configDir>${buildDir}/amc_config</configDir>
<mopinftlDir>${buildDir}/mopinftl</mopinftlDir>
<proj.varient>V64</proj.varient>
<amcgdd.dir>${srcDir}/gdd</amcgdd.dir>
<ginftl.dir>${buildDir}/ginftl${env.BUILD_VERSION}${proj.varient}</ginftl.dir>
<infgn.dir>${srcDir}/infgn</infgn.dir>
<include.xerces-c2>${env.XERCES_HOME}/include</include.xerces-c2>
<usr>/usr</usr>
<lib.openssl>${env.OPENSSL_HOME}/lib</lib.openssl>
<lib.ace>${env.ACE_HOME}/lib</lib.ace>
<lib.local64>/usr/local64/lib</lib.local64>
<gamc.dir>${buildDir}/gamc${env.BUILD_VERSION}${proj.varient}</gamc.dir>
<lib.local>/usr/local/lib</lib.local>
<lib.usr>/usr/lib64</lib.usr>
<lib.xerces-c2>${env.XERCES_HOME}/lib</lib.xerces-c2>
<lib.xerces-c>xerces-c</lib.xerces-c>
<include.ace>${env.ACE_HOME}</include.ace>
<include.local64>/usr/local64/include</include.local64>
<include.openssl>${env.OPENSSL_HOME}/include</include.openssl>
    </properties>
  
    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.1.0</version>
                <extensions>true</extensions>

                <configuration>
                    <layout>NarLayout20</layout>
                <linker>   <!-- Linkers-->
                   <name>icpc</name>
                  <options>
<option>-L${lib.openssl}</option>
<option>-L${lib.ace}</option>
<option>-L${lib.local64}</option>
<option>-L${gamc.dir}/lib</option>
<option>-L${lib.local}</option>
<option>-L${lib.usr}</option>
<option>-L${lib.xerces-c2}</option>
<option>-l${lib.xerces-c}</option>
                   </options>
                </linker>
 
<cpp>
<name>icpc</name>
<sourceDirectory>${srcDir}</sourceDirectory>
<includes>
             <include>**/mro/src/AMC_MroMainFunc.cpp</include>
<include>**/mro/src/AmcApis.cpp</include>
<include>**/log/src/*.cpp</include> 
<include>**/com/src/*.cpp</include>  
</includes>
            <includePaths>

<!-- <includePath>${srcDir}/log/inc</includePath>
          <includePath>${srcDir}/mro/inc</includePath>
          <includePath>${srcDir}/com/inc</includePath>
          <includePath>${srcDir}/shr</includePath>
          <includePath>${srcDir}/pub</includePath>
  
         <includePath>${configDir}/v${env.BUILD_VERSION}/pub</includePath>
          <includePath>${mopinftlDir}/v${env.BUILD_VERSION}/pub</includePath>
          <includePath>${buildDir}/gamc${env.BUILD_VERSION}${proj.varient}/cnt</includePath>
          <includePath>${buildDir}/gamc${env.BUILD_VERSION}/amcapi</includePath>-->
  
  <!--<includePath>${amcgdd.dir}</includePath>
  <includePath>${amcgdd.dir}/cnt</includePath> 
          <includePath>${ginftl.dir}/cnt</includePath>
  <includePath>${infgn.dir}</includePath>
          <includePath>${include.xerces-c2}</includePath>
          <includePath>${usr}</includePath>
          <includePath>${usr}/include</includePath>
          <includePath>/usr/lib/x86_64-redhat-linux5E/include</includePath>-->






  
          <includePath>${srcDir}/com/inc</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/shr</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/pub</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/gdd</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/infgn</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/log/inc</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/mro/inc</includePath>
  <includePath>${include.xerces-c2}</includePath>
  <includePath>/usr/include</includePath>
  <includePath>${include.ace}</includePath>
  <includePath>/usr/lib/x86_64-redhat-linux5E/include</includePath>
  <!--<includePath>${include.local64}</includePath> 
  <includePath>${include.openssl}</includePath>-->
  
  
  
   
          
  
            </includePaths>
    
   <!--Compiler args -->
            <options>
              <option>-c</option>
<option>-g</option>
<option>-DNO_LIANT</option>
<option>-DUNIX</option>
<option>-DXERCES_2</option>
<option>-D_USE_GMP</option>
<option>-pthread</option>
<option>-D__linux</option>
<option>-fPIC</option>
<option>-ansi</option>
<option>-D__ACE_INLINE__</option>
<option>-DAMC_COMP</option>
<option>-D__linux_</option>
<option>-D__osf__</option>
<option>-D__linux__</option>
            </options>
            <clearDefaultOptions/>
            <compileOrder/>
</cpp>
        <libraries>
             <library>
                 <type>shared</type>
             </library>
         </libraries>
       </configuration>
    </plugin>
<plugin>
    <groupId>com.coderplus.maven.plugins</groupId>
    <artifactId>copy-rename-maven-plugin</artifactId>
    <version>1.0.1</version>
    <executions>
      <execution>
        <id>rename-file</id>
        <phase>install</phase>
        <goals>
          <goal>rename</goal>
        </goals>
        <configuration>
          <sourceFile>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/com/target/nar/lib/amd64-Linux-icpc/shared/libcom-main.so</sourceFile>
          <destinationFile>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/com/target/libamcapi.so</destinationFile>
        </configuration>
      </execution>
    </executions>
  </plugin>
  </plugins>
</build>    
</project>


If you want to create executable then define the library as executable.
-------------------------------------------------------------------------------------

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
<parent>
 <groupId>com.amdocs.amcApiPar</groupId>
 <artifactId>amcApiPar</artifactId>
 <version>0.0.1-SNAPSHOT</version>
</parent>

    <groupId>mro</groupId>
    <artifactId>amc_mro</artifactId>
    <packaging>nar</packaging>
    <version>main</version>

    <properties>
        <skipTests>true</skipTests>
<base.dir>${env.HOME}/workspace/AMC_Build</base.dir>
<srcDir>${base.dir}/${env.BUILD_VERSION}/amcapi</srcDir>
<buildDir>${base.dir}/proj</buildDir>
<configDir>${buildDir}/amc_config</configDir>
<mopinftlDir>${buildDir}/mopinftl</mopinftlDir>
<proj.varient>V64</proj.varient>
<amcgdd.dir>${srcDir}/gdd</amcgdd.dir>
<ginftl.dir>${buildDir}/ginftl${env.BUILD_VERSION}${proj.varient}</ginftl.dir>
<infgn.dir>${srcDir}/infgn</infgn.dir>
<include.xerces-c2>${env.XERCES_HOME}/include</include.xerces-c2>
<usr>/usr</usr>
<lib.openssl>${env.OPENSSL_HOME}/lib</lib.openssl>
<lib.ace>${env.ACE_HOME}/lib</lib.ace>
<lib.local64>/usr/local64/lib</lib.local64>
<gamc.dir>${buildDir}/gamc${env.BUILD_VERSION}${proj.varient}</gamc.dir>
<lib.local>/usr/local/lib</lib.local>
<lib.usr>/usr/lib64</lib.usr>
<lib.xerces-c2>${env.XERCES_HOME}/lib</lib.xerces-c2>
<lib.xerces-c>xerces-c</lib.xerces-c>
<include.ace>${env.ACE_HOME}</include.ace>
<include.local64>/usr/local64/include</include.local64>
<include.openssl>${env.OPENSSL_HOME}/include</include.openssl>
<lib.amcapi>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/com/target</lib.amcapi>
    </properties>
  
    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.1.0</version>
                <extensions>true</extensions>

                <configuration>
                    <layout>NarLayout20</layout>
                <linker>
                   <name>icpc</name>
                  <options>
<option>-L${lib.openssl}</option>
<option>-L${lib.ace}</option>
<option>-L${lib.local64}</option>
<option>-L${gamc.dir}/lib</option>
<option>-L${lib.local}</option>
<option>-L${lib.usr}</option>
<option>-L${lib.xerces-c2}</option>
<option>-L${lib.amcapi}</option>
<option>-l${lib.xerces-c}</option>
<option>-lamcapi</option>
<option>-lssl</option>
<option>-lcrypto</option> 
                   </options>
                </linker>
 
<cpp>
<name>icpc</name>
<sourceDirectory>${srcDir}</sourceDirectory>
<includes>
<include>**/log/src/amc1_Logger.cpp</include>
             <include>**/mro/src/*.cpp</include>  
</includes>
<excludes>
<exclude>**/mro/src/AMC_MroMainFunc.cpp</exclude>
<exclude>**/mro/src/AmcApis.cpp</exclude>
</excludes>
            <includePaths>

  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/log/inc</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/mro/inc</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/dm/inc</includePath>
          <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/com/inc</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/shr</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/pub</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/gdd</includePath>
  <includePath>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/infgn</includePath>
  <includePath>${include.xerces-c2}</includePath>
  <includePath>/usr/include</includePath>
  <includePath>${include.ace}</includePath>
  <includePath>/usr/lib/x86_64-redhat-linux5E/include</includePath>
  
            </includePaths>
    
   <!--Compiler args -->
            <options>
             <option>-c</option>
<option>-g</option>
<option>-DNO_LIANT</option>
<option>-DUNIX</option>
<option>-DXERCES_2</option>
<option>-D_USE_GMP</option>
<option>-pthread</option>
<option>-D__linux</option>
<option>-fPIC</option>
<option>-ansi</option>
<option>-D__ACE_INLINE__</option>
<option>-DAMC_COMP</option>
<option>-D__linux_</option>
<option>-D__osf__</option>
<option>-D__linux__</option>
<option>-D_REENTRANT</option>
            </options>
           
</cpp>
        <libraries>
             <library>
                 <type>executable</type>
             </library>
         </libraries>
       </configuration>
    </plugin>
<plugin>
    <groupId>com.coderplus.maven.plugins</groupId>
    <artifactId>copy-rename-maven-plugin</artifactId>
    <version>1.0.1</version>
    <executions>
      <execution>
        <id>rename-file</id>
        <phase>install</phase>
        <goals>
          <goal>rename</goal>
        </goals>
        <configuration>
          <sourceFile>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/mro/target/nar/bin/amd64-Linux-icpc/amc_mro</sourceFile>
          <destinationFile>/devuser/mnc/mnc/bismayam/workspace/AMC_Build/main/amcapi/mro/target/amc_mro</destinationFile>
        </configuration>
      </execution>
    </executions>
  </plugin>
  </plugins>
</build>    
</project>


To copy the resources .
-----------------------------


<plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>copy-mro-src</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${bin.dir}</outputDirectory>
              <resources>          
                <resource>
                 <directory>${src.dir}/mro/src</directory>
                  <includes>
                  <include>*.ksh</include>
                  </includes>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
 
 
 <execution>
            <id>copy-amccore-pi</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${bin.dir}</outputDirectory>
              <resources>          
                <resource>
                 <directory>${base.dir}/${env.BUILD_VERSION}/amccore/pi/src</directory>
                  <includes>
                  <include>/*.sql</include>
                  </includes>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
</plugin>


Thank You.

Friday, 8 May 2015

Create Multiple Jars from single pom.xml in Maven

Note : It is recommended to create a single from one pom. If possible then try to decompose the package structure to create multiple projects and create one jar for one project. If it is not helpful then use the below process to create multiple jars from single pom.


<plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>

          <execution>
            <id>any_Id</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
<finalName>JarOne</finalName>
                <encoding>ISO-8859-1</encoding>
                <classifier>Core</classifier> <!-- This will be appended with the jar created with finalName tag value if present-->
               <includes>
<include>**/*.*</include>              
              </includes>
              <excludes>
                          <exclude>**/test.*</exclude>
              </excludes>  
            </configuration>
          </execution>

 <execution>
            <id>any_Id</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
<finalName>JarOne</finalName>
                <encoding>ISO-8859-1</encoding>
                <classifier>NonCore</classifier> <!-- This will be appended with the jar created-->
               <includes>
<include>**/*.*</include>              
              </includes>
              <excludes>
                          <exclude>**/test.*</exclude>
              </excludes>  
            </configuration>
          </execution>

 </executions>
</plugin>

Create more than one <execution> to create individual jars. The names of the jars will be appended with the value of <classifier> tag. If you are including <finalName> tag then the jar name will be as follows.

JarOne-Core.jar
JarOne-NonCore.jar


Thursday, 7 November 2013

Custom annotation in JPA

Entry in orm.xml

<persistence-unit-metadata>
<persistence-unit-defaults>
<entity-listeners>
<entity-listener class="com.wdpr.dataaccess.jpa.EntityAuditListener" />
<entity-listener class="com.wdpr.dataaccess.jpa.SpaceRTrimListener" />
</entity-listeners>
</persistence-unit-defaults>
</persistence-unit-metadata>

Listener class

package com.wdpr.dataaccess.jpa;

import com.wdpr.dataaccess.annotation.RTrim;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

public class SpaceRTrimListener
{
  private static final Map<Class<?>, Set<Field>> trimProperties = new HashMap();
  private static final String EMPTY_STRING = "";
  private static final String RIGHT_TRIM_PATTERN = "\\s+$";

  @PrePersist
  @PreUpdate
  public void rTrimnSpaces(Object entity)
    throws Exception
  {
    for (Field fieldToTrim : getTrimProperties(entity.getClass()))
    {
      String propertyValue = (String)fieldToTrim.get(entity);
      if (propertyValue != null)
      {
        fieldToTrim.set(entity, rightTrim(propertyValue));
      }
    }
  }

  private String rightTrim(String propertyValue)
  {
    if ((propertyValue != null) && (!"".equals(propertyValue.trim())))
    {
      propertyValue = propertyValue.replaceAll("\\s+$", "");
    }
    return propertyValue;
  }

  private Set<Field> getTrimProperties(Class<?> entityClass) throws Exception
  {
    if (Object.class.equals(entityClass))
    {
      return Collections.emptySet();
    }
    Set propertiesToTrim = (Set)trimProperties.get(entityClass);
    if (null == propertiesToTrim)
    {
      propertiesToTrim = new HashSet();
      for (Field field : entityClass.getDeclaredFields())
      {
        if (field.getAnnotation(RTrim.class) == null)
          continue;
        if (field.getType().equals(String.class))
        {
          field.setAccessible(true);
          propertiesToTrim.add(field);
        }
        else {
          String errorMessage = "Entity : " + entityClass.getName() + " Field : " + field.getName() + " of type : " + field.getType() + " cannot use Rtrim annotation";

          throw new IllegalArgumentException(errorMessage);
        }
      }

      trimProperties.put(entityClass, propertiesToTrim);
    }
    return propertiesToTrim;
  }

}

Monday, 5 November 2012

Number validation in JavaScript

var
customerNumberInput = document.getElementById("customerNumber");
var customerNumber = customerNumberInput != null ? customerNumberInput.value : "";
//Added for FY12 Enhancements changes by BM54284
if(customerNumber){
customerNumber= customerNumber.replace(
/^\s+|\s+$/, '');
if(isNaN(customerNumber) == true)
return warnInvalid(customerNumberInput, "Please provide Numeric value for Customer Number.");
if(customerNumber.length != 9)
return warnInvalid(customerNumberInput, "Please provide the valid Customer Number.");
}

Tuesday, 30 October 2012

excel format for JSP

<%
response.setContentType(
"application/vnd.ms-excel");
response.setHeader(
"Content-Disposition","attachment;filename=\"CurrentCustomerList.xls\"");
response.setHeader(
"Pragma", "public");
response.setHeader(
"Cache-Control", "max-age=0");
Iterator iterator = (Iterator) request.getAttribute(
"iterator");%>

Comparator for User defined object compare

import

java.util.Comparator;
public
class CountyDTO {
private
String state;
private
String country;
public
void setState(String state) {
this
.state = state;
}
public
void setCountry(String country) {
this
.country = country;
}
public
String getState() {
return
state;
}
public
String getCountry() {
return
country;
}
/**
*
@author BM54284
* Comparater for sorting the States for Task 2
*/
public
static enum CountyComparator implements Comparator<CountyDTO> {
STATE_SORT
{
public
int compare(CountyDTO o1, CountyDTO o2) {
if
((null != o1 && null != o1.getState())
&& (null
!= o2 && null != o2.getState())) {
return
o1.getState().compareTo(o2.getState());
} else
{
return
0;
}
}
},
COUNTRY_SORT
{
public
int compare(CountyDTO o1, CountyDTO o2) {
if
((null != o1 && null != o1.getCountry())
&& (null
!= o2 && null != o2.getCountry())) {
return
o1.getCountry().compareToIgnoreCase(o2.getCountry());
} else
{
return
0;
}
}
};
public
static Comparator<CountyDTO> getComparator(
final
CountyComparator... multipleOptions) {
return
new Comparator<CountyDTO>() {
public
int compare(CountyDTO o1, CountyDTO o2) {
for
(CountyComparator option : multipleOptions) {
int
result = option.compare(o1, o2);
if
(result != 0) {
return
result;
}
}
return
0;
}
};
}
}
}




//Call to that comparater


List<CountyDTO> contryandstate = getCountyFinder().getState();
contryandstate.addAll(getAdditionalCounty());
Collections.sort(contryandstate, CountyComparator.getComparator(CountyComparator.COUNTRY_SORT
,CountyComparator.STATE_SORT));




Saturday, 22 September 2012

How to get EnvironmentSpecificParam value from xml in JSP and Controller

 //Make the Entry in applicationContext.xml

<context:property-placeholder properties-ref="environmentSpecificParam" />

<util:properties id="environmentSpecificParam">

<prop key="datasourceJNDI">Something</prop>
        <prop key="tablePrefix">Something.</prop>
        <prop key="schema">Something</prop>
        <prop key="encryptionKey">Something</prop>
        <prop key="databaseUserId">Something</prop>
        <prop key="databasePassword">Something</prop>
       
        <!-- Industry Potential DataSource Details -->
        <prop key="indPotentialDatasourceJNDI">Something</prop>
        <prop key="tablePrefix">Something.</prop>
        <prop key="indPotentail_schema">Something</prop>
       
       
        <!-- ScoreCard DataSource Details -->
        <prop key="scoreCardDatasourceJNDI">Something</prop>
        <prop key="scoreCardTablePrefix">Something.</prop>
        <prop key="scoreCardSchema">Something</prop>
        <prop key="scoreCardDatabaseUserId">Something</prop>
        <prop key="scoreCardDatabasePassword">Something</prop>
       
        <prop key="SomeURL">https://some.js</prop>

        <!--Added by BM54284 -->
        <prop key="logout">https://abc.com/servlet/LogOutServlet</prop>


</util:properties>



//Get this in Controller like

@Value("#{environmentSpecificParam.logout}")
    private String logout;
@Value("#{environmentSpecificParam.gscURL}")
    private String SomeURL;

//Add like this to get in JSP
model.addAttribute("someURL", SomeURL);


//Get this in JSP like
<script type="text/javascript" src="${SomeURL}"></script>

Disable the content and uncheck the check boxes on load of the body

//Call  this function on load of the body 

function disableAndUncheckOnLoad(){
$('.wrap').attr('disabled', 'disabled');
$('input').attr('disabled', 'disabled');
$('input[type=checkbox]').each(function(){
  this.checked = false;
});


Friday, 21 September 2012

Date Validation in JavaScript

/**
 * End Date Validation
 * @returns {Boolean}
 */
function endDateCheck(){
    var startDatechk = $('#datepickerStart').val();
    var enddatechk = $('#datepickerEnd').val();
    if(startDatechk != ''){
        if(Date.parse(enddatechk) > new Date() || Date.parse(enddatechk) < Date.parse(startDatechk)){
            alert("End date should be in between the start date and current date");
            $('#datepickerEnd').val('');
            return false;
        }
    }else if(Date.parse(enddatechk) > new Date() ){
        alert("End date should be in between the start date and current date");
        $('#datepickerEnd').val('');
        return false;
    }
    $('#datepickerEnd').datepicker("hide");
    return false;
}

/**
 * Start Date Validation
 * @returns {Boolean}
 */
function startDateCheck(){
    var startDatechk = $('#datepickerStart').val();
    var enddatechk = $('#datepickerEnd').val();
    if(Date.parse(startDatechk) > new Date() || Date.parse(enddatechk) < Date.parse(startDatechk)){
        alert("Start date should be bofore current date and end date");
        $('#datepickerStart').val('');
        return false;
    }
    $('#datepickerStart').datepicker("hide");
    return false;
}



//Call this onLoad of the body

$(document).ready(function() {
var startYear = new Date().getFullYear() - 3;
var dateRange = startYear+":"+new Date().getFullYear();
 $('#datepickerStart').datepicker({
         yearRange: dateRange,
        changeMonth: true,
        changeYear: true,
        showOn : 'button',
        buttonImage : '/dlrmap/images/icons/calendar.gif',
        buttonImageOnly : true
    });
   
    $('#datepickerEnd').datepicker({
           yearRange: dateRange,
        changeMonth: true,
        changeYear: true,
        showOn : 'button',
        buttonImage : '/dlrmap/images/icons/calendar.gif',
        buttonImageOnly : true
    });
});


//Use <script src='${pageContext.request.contextPath}/resources/jquery-ui-1.8.17.custom.min.js'></script>

Difference between class level and object locking and static object lock

1) Class level locking will lock entire class, so no other thread can access any of other synchronized blocks. 2) Object locking will lo...