Home Navigation

Thursday, 6 October 2016

Publish jar to file system local repository maven deploy

  • Create a local repository directory for example C:\localRepo
  • Here you have two way to publish jar in local repo, either you can create a batch script to publish all of the jars together or open command terminal and execute batch command one by one.
Command Line:
>mvn install:install-file -DgroupId=%groupId% -DartifactId=%artifactid% -Dversion=%versionId% -Dpackaging=jar -Dfile=%JarFile% -DlocalRepositoryPath=C:\localRepo 

BatchScript:
I have added eight jar files to publish, you can adjust the script according to your need.

@echo off
title repository workbrain local setup
color 1f
:: ###################################
cls
:start
echo Maven local workbrain repository setup
call mvn install:install-file -Dfile=axis.jar  -DgroupId=axis -Dversion=axis -DartifactId=axis -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=commons-discovery.jar  -DgroupId=commons-discovery -Dversion=commons-discovery -DartifactId=commons-discovery -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=commons-logging.jar  -DgroupId=commons-logging -Dversion=commons-logging -DartifactId=commons-logging -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=jaxrpc.jar  -DgroupId=jaxrpc -Dversion=jaxrpc -DartifactId=jaxrpc -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=log4j.jar  -DgroupId=log4j -Dversion=log4j -DartifactId=log4j -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=saaj.jar  -DgroupId=saaj -Dversion=saaj -DartifactId=saaj -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=soap.jar  -DgroupId=soap -Dversion=soap -DartifactId=soap -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
call mvn install:install-file -Dfile=wsdl4j.jar  -DgroupId=wsdl4j -Dversion=wsdl4j -DartifactId=wsdl4j -Dpackaging=jar -DlocalRepositoryPath=C:\localRepo
echo.
echo ######################################################
echo All done :-)
echo ######################################################
pause>null



Open pom.xml file of your project and add the below tag under repositories tag


<repository>
      <id>internal local repository</id>
       <url>file://C:\localRepo</url>
</repository>

Then you can add your dependency in the  dependency tag.

Build your project

Publish file system library (jar, war, ear) to remote repository ( nexus) using maven deploy command.

I have created a batch script to publish all the libraries inside a directory, you have to just place the batch script in the directory and execute it.

Before you execute the script make sure that you have defined a server in maven settings.xml (it will be found in {USER_HOME}/.m2 directory)

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
    <server>
      <id>central</id>
    </server>
    <server>
      <id>snapshots</id>
    </server>
    <server>
  <id>nexus</id> <!-- this is the repository id in batch script -->
  <username>deployment</username>
  <password>deployment123</password>
  </server>
  </servers>

Batch script to publish jars

@echo off
color 1f
::#############################################################################
cls
:start

set repositoryUrl=http://192.168.0.19:8082/nexus/content/repositories/releases/
set repositoryId=nexus
set packaging=jar
set groupId={give_a_group_id}
set versionId={give_a_version}

setlocal EnableDelayedExpansion

echo Reading jar files to publish nexus repository %repositoryUrl%
for %%a in (*.jar) do (
    echo deploying jar file %%~na
    call mvn deploy:deploy-file -DgroupId=%groupId% -DartifactId=%%~na -Dversion=%versionId% -Dpackaging=jar -Dfile=%%~na.jar -DrepositoryId=%repositoryId% -Durl=%repositoryUrl%              
               
)

echo Finished publishing to nexus repository %repositoryUrl%

pause > null

Set cusomize class loader policy to PARENT_LAST for enterprise application in WAS

So, what is the best way to customize the classloader policy for an EAR application? we can consider 4 options.
  • Change class loader policy to PARENT_LAST after every deployment from administrative console
  • Set the server profile setting to use a PARENT_LAST classloader policy for all apps. However this might not be a POLICY for all of the app deployed in WAS.
  • Write and execute a jython script after every publish to set the classloader policy.
  • Create deployment.xml using RSA deployment descriptor editor J2EE plugin tool

You can choose any of the option according to your business needs.
But the best thing would be found out a solutions to application specific and set at EAR application project level so that any topology can suite your solution.

So here the best approach I think, create a deployment.xml file and put it in the EAR application root level.

<?xml version="1.0" encoding="UTF-8"?>
<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_124111296412322">
 <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_23423402344" startingWeight="1" warClassLoaderPolicy="SINGLE">
    <classloader xmi:id="Classloader_23432543596" mode="PARENT_LAST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_12411129640345" startingWeight="10000" uri="yourwarproject.war">
      <classloader xmi:id="Classloader_12411324234"/>
    </modules>
  </deployedObject>
</appdeployment:Deployment>

You can use any method to package your application, you can generate/copy deployment.xml via ANT or any tool.

    <ear destfile="${artifactsDir}/${earName}.ear" appxml="${projectName}_EAR/application.xml">
         <fileset dir="${artifactsDir}" includes="${yourwarproject}.war"/>
         <fileset dir="${projectName}_EAR/" includes="deployment.xml"/>
    </ear>

Wednesday, 5 October 2016

WebSphere Deployment Descriptors

  • Open WebSphere Programming Model Extensions Descriptor : (For applications that target WebSphere Application Server) The WebSphere bindings section provides a place to add WebSphere Programming Model Extensions.
  • Open WebSphere Bindings: (For applications that target WebSphere Application Server) The WebSphere bindings section provides a place to add users and groups to the security roles.
  • Open WebSphere Extensions: (For applications that target WebSphere Application Server) The WebSphere Extensions section provides a place to add WebSphere Extensions.
Use the General Information section to view the display name and description for the enterprise application, as stored in the application.xml file.

Class loader in JVM, J2EE and WAS

Lets first discuss a little  bit about the class loader. Class loaders enable the JVM to load Java classes for use by applications during deployment and operation.

When you start a JVM, it uses the following class loaders:

  • Bootstrap class loader Loads only the core Java libraries in...
    JAVA_HOME/jre/lib
    This class loader, which is part of the core JVM, is written in native code.
  • Extensions class loader, Loads the code in the extensions directories...JAVA_HOME/jre/lib/ext ...or any other directory specified by the property...
    java.ext.dirs system, This class loader is implemented by the class... sun.misc.Launcher$ExtClassLoader
  • Application class loader Loads code found on...
    java.class.path
    ...which ultimately maps to the system CLASSPATH variable. This class loader is implemented by the class... sun.misc.Launcher$AppClassLoader
WAS and Java EE application class loaders

When working with Java EE applications, two additional types of class loaders are involved:

  • The application server class loaders, which loads all of the classes needed for the application server in which the enterprise applications are running.
  • The application class loaders, which loads the application classes as defined in web.xml


WAS provides several custom delegated class loaders, similar to those class loaders, but it implements the extensions as OSGi packages.

It was just an introduction how class loader loads library, 

Monday, 3 October 2016

Installing WebSphere 8.5.5.2 in RSA, Java 7 Profile

Rational Software Architect is a modeling and development environment that uses the Unified Modeling Language (UML) for designing architecture for C++ and Java EE (JEE) applications and web services. Rational Software Architect is built on the Eclipse open-source software framework and includes capabilities focused on architectural code analysis, C++, and model-driven development (MDD) with the UML for creating applications and web services.

By default WebSphere 8.5.5.0 supports Java 6, so to install java 7 profile in existing WebSphere 8.5.5.0 is a bit complicated. So to install you have to login to IBM Passport Advantage with your IBM id and access to passport advantage site and download the repo.

WebSphere 8.5.5.2, supports java 7 profile and ships with Java 7 SDK.

If you wish to install you can download it from http://www.ibm.com/support/docview.wss?uid=swg24037250  and login with your IBM user id. After login go to the download section and download the highlighted sources.

Also download the java 7 sdk from the same page 7.1.3.10_0001-WS-IBMWASJAVA-Win.zip

To install Fix Pack 8.5.5.2 using a local repository, point Installation Manager to the repository.xml file on your local machine. If part1 and part2 .zip files exist, unzip the part1 and part2 .zip files to the same folder on your local machine. Both .zip files are required for installation of the fix pack. When unzipping part2, the Windows operating system might warn you that a directory with the same name already exists. Allow the tool to merge the directories; the tool does not overwrite any files.

To add the repository:
  1. Start Installation Manager. 
  2. In the top menu, click File > Preferences. 
  3. Select Repositories. 
  4. Click Add Repository. 
  5. Enter the path to the repository.xml file in the location containing the repository files.
    • This is a sample path for a local repository on Windows operating system:C:\repositories\product_name\local-repositories
    • This is a sample path for a local repository on AIX, HP-UX, Linux, Solaris operating system:/var/repositories/product_name/local-repositories
Also add the 7.1.3.10_0001-WS-IBMWASJAVA-Win.zip repository. ( you don't have to unzip this source)

Installation
  1. Click install
  2. Then follow the instruction in the screen, select the websphere 8.5.5.2 and Java 7 
  3. Click next next

You might see some error while installing the websphere 8.5.5.2 if you have existing websphere installed, so make sure to uninstall/delete the existing one.

After successful installation, go to the directory location {WEBSPHERE_INSTALLATION_LOCATION}/bin and execute the below command

>managesdk.bat -listAvailable
>managesdk.bat -enableProfile -profileName {ProfileName} -sdkname {sdkname}

{profileName} = you can see from RSA server section, when you right click on server and properties
{sdkname} = it will show the name of sdk once you execute the first command

Thursday, 29 September 2016

DB2 Some useful tips

Check view Definition/Contents:

select name, cast(statement as  varchar(8000)) from SYSIBM.SYSVIEWS where name={VIEW_NAME} for read only;

DB2 Dummy table: sysibm.sysdummy1

DB2 optimize query to control result set:

- with ur for read only
- fetch first n rows only
- optimize for 1 row