Friday, June 28, 2013

Exclude transitive dependency while building(maven) a WAR file.

Sometime you want to copy ONLY the dependency jar in WEB-INF/lib directory of the WAR file.
Because service hosting product already provided the transitive dependencies.
You can achieve this requirement using the proper exclusions with the dependency.

Let's say your project has following dependency,

<dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.registry.common</artifactId>
            <version>4.2.0-SNAPSHOT</version>      
</dependency>

1. First run the mvn dependency:tree command to get the dependency tree of your project. After that copy the output  to some text file and search above jar name(org.wso2.carbon.registry.common).

Let's say you have found following sub tree in the dependency tree of your project .

+- org.wso2.carbon:org.wso2.carbon.registry.common:jar:4.2.0-SNAPSHOT:provided
  +- commons-beanutils.wso2:commons-beanutils:jar:1.8.0.wso2v1:provided
  \- org.wso2.carbon:org.wso2.carbon.feature.mgt.services:jar:4.2.0-SNAPSHOT:provided
     +- org.wso2.carbon:org.wso2.carbon.feature.mgt.core:jar:4.2.0-SNAPSHOT:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.artifact.repository:jar:1.1.100.v20110519:provided
     |  +- org.eclipse.equinox:org.eclipse.equinox.p2.director:jar:2.1.0.v20110504-1715:provided
     |  +- org.eclipse.equinox:org.eclipse.equinox.p2.metadata.repository:jar:1.2.0.v20110511-1359:provided
     |  \- org.eclipse.equinox:org.eclipse.equinox.simpleconfigurator:jar:1.0.301.v20120828-033635:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.core:jar:2.1.0.v20110502-1955:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.engine:jar:2.1.0.v20110511:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.metadata:jar:2.1.0.v20110510:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.repository:jar:2.1.0.v20110601:provided
     \- org.eclipse.equinox:org.eclipse.equinox.common:jar:3.6.100.v20120522-1841:provided

2. Now, if you want to prevent packaging its transitive dependency you should update the above dependency as follow.

<dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.registry.common</artifactId>
            <version>4.2.0-SNAPSHOT</version> 
           <exclusions>
                  <exclusion>
                      <groupId>commons-beanutils.wso2</groupId>
                      <artifactId>commons-beanutils</artifactId>
                  </exclusion>

          </exclusions>     
</dependency>

OR , you can  define new dependency with the scope as provided.

<dependency>
            <groupId>commons-beanutils.wso2</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.0.wso2v1</version> 
            <scope>provided</scope>               
</dependency>

Wednesday, June 26, 2013

Export data source configs from one Application Server node and import to another.


Here, we used registry checkin client tool to export data source configurations from WSO2 Application Server  registry and import to another Application Server instance.

i) When you create a data source from wizard, it will be stored in registry as a XML resource.

/_system/config/repository/components/org.wso2.carbon.ndatasource



ii) Copy checkin-client.sh or checkin-client.bat to AS_HOME/bin.

ii) Copy the checkin-client-4.5.3.jar to the AS_HOME/repository/lib.

iii) Start the Application server and go the bin directory and execute the following command to dump the data source configurations.

sh checkin-client.sh co https://localhost:9443/registry/_system/config/repository/components/org.wso2.carbon.ndatasource -u admin -p admin -f ds.dump

Now all the data source configurations will dump to ds.dump file (it is in the bin directory).

iv) Execute the following command to import the data source configurations to next Application Server (9444).

sh checkin-client.sh ci https://localhost:9444/registry/_system/config/repository/components/org.wso2.carbon.ndatasource -u admin -p admin -f ds.dump file

v) Restart the server.
 
Resource location : https://svn.wso2.org/repos/wso2/people/ajith/blog/checkin-client/

Documentation : http://docs.wso2.org/wiki/display/Governance460/Check-in+Client