Showing posts with label others. Show all posts
Showing posts with label others. Show all posts

Wednesday, April 4, 2012

Ant Task: Init

Ant Task: Init

 

Creates and initializes the metadata table in the schema.

Usage:

 

<flyway:init />

Configuration:


Driver = flyway.driver: The fully qualified classname of the jdbc driver to use to connect to the database , Required=YES,

URL = flyway.url: The jdbc url to use to connect to the database,

User = flyway.user: The user to use to connect to the database,

Password = flyway.password: The password to use to connect to the database, Required=NO, Default       Value=blank,

Schemas = flyway.schemas: Comma-separated list of schemas managed by Flyway. The first schema in the list will be the one containing the metadata table,Required=NO, Default Value= default schema of the connection,

Table =  flyway.table: The name of Flyway's metadata table.By default (single-schema mode) the metadata table is placed in the default schema for the connection provided by the     datasource.When the flyway.schemas property is set (multi-schema mode), the metadata table is placed in the first schema of the list,Required=No,Default Value = schema_version,

InitialVersion = flyway.initialVersion: The initial version to put in the database, Required=NO, Default Value=0,

InitialDescription = flyway.initialDescription: The description of the initial version, Required=NO, Default Value=<< Flyway Init >>,

ClassPath = flyway.classpath: The Ant classpath used to load the JDBC driver and the migrations, Required=NO,

ClassPathref = flyway.classpathref: The Ant classpath reference used to load the JDBC driver and the migrations, Required=NO.

Sample configuration;


<property name="flyway.driver" value="org.hsqldb.jdbcDriver"/>
<property name="flyway.url" value="jdbc:hsqldb:file:/db/flyway_sample"/>
<property name="flyway.user" value="SA"/>
<property name="flyway.password" value="mySecretPwd"/>
<property name="flyway.schemas" value="schema1,schema2,schema3"/>
<property name="flyway.table" value="schema_history"/>
<property name="flyway.initialVersion" value="1.0"/>
<property name="flyway.initialDescription" value="Base Migration"/>


Sample output

 

 

Friday, January 27, 2012

How to generate build.xml file

This example shows how to generate the build.xml file. You may say that build.xml file is the backbone of ANT (Another Neat Tool) technology. Each build.xml file contains only one project name and at least one target. The project tag has only three attributes:



Project

Attribute
Description 
Requirement
name
project name
not necessary
default
target name which called by default
not necessary
basedir
the base directory having all path, it contain absolute path
not necessary




<project name="My Project" default="compile" basedir=".">


The project tag is used to create our project and its attributes are used to handle further processing of the project. The name attribute is used to specify the project name and the default attribute is used to specify which target will be called as default when the program will run and the basedir attribute is used to calculate the absolute path of the parent directory. 



An another tag is Target tag which has following five attributes:
Target
Attribute
Description
Requirement
name
target name
necessary
depends
depends on another target
not necessary
if
the name of the property that must be set in order for this target to execute.
not necessary
unless
the name of the property that must not be set in order for this target to execute.
not necessary
description
short description about target
not necessary





<target name="buildWar" depends="init" description="build a war file"/>
<target name="init" if="build"/>
<target name="init" unless="build"/>



In the target tag, name attribute is used for target name and the depends attribute is used to give sequence of target, i.e., which target will execute first, one target may depend on one or more other targets. The if attribute is used in case of condition, whether property exists or not; then this target will be executed and unless attribute is used as like else condition whether property does not exist, the target will not be executed and the description attribute is used for only giving details about target.



Next tag is property tag which has following four attribute:
Property
Attribute
Description
Requirement
name
name of the property, which is case-sensitive
not necessary
value
name of task attribute, this is done by placing the property name between "${"name }" in the attribute value
necessary
location
it contain property name
not necessary
file
name of the property file
not necessary



<property name="build" value="${build}"/> 
<property name="src" location="src"/> 
<property file="build.properties"/>

In the property tag, name attribute is used for property name; it is case sensitive. The value tag is used to give the task which will be the name of property in this format "${name}", and the location tag is used to specify the location of task where it performs and the file tag is used to import all properties of ant file. The complete build.xml file structure is as follows:


<project name="My Project" default="jar" basedir=".">

<property name="dir.src" value="src"/>
<property name="dir.build" value="build"/>
<property name="dir.dest" value="dest"/>

<target name="clean" description="Removing the all generated files.">
<delete dir="${dir.build}"/>
<delete dir="${dir.dest}"/>
</target>

<target name="prepare" depends="clean">
<mkdir dir="${dir.build}"/>
<mkdir dir="${dir.dest}"/>
<mkdir dir="${dir.src}"/>
</target>

<target name="compile" depends="prepare" description="Compilation of all source code.">
<javac srcdir="${dir.src}" destdir="${dir.build}"/>
</target>

<target name="jar" depends="compile" description="Generates news.jar file in to the 'dest' directory.">
<jar jarfile="${dir.dest}/news.jar" basedir="${dir.build}"/>
</target>

</project>

The above build.xml file is used to create directory, compile source code, create jar file and clean the directory if already exists. To check the program, simply copy and paste the above code and give appropriate path; then run with ant command on the command prompt. 

The output shows that a jar file named news.jar is created but in this jar file only manifest file is created. When you make a java file in the src folder and run with ant command, the jar file is created completely.


class Hello
{
  public static void main(String args[]){
  System.out.println("muraliraj");
  }
}


To check your program, compile it with ant command on the console; 


then the following output will be displayed:  Build Successful




Wednesday, January 11, 2012

Create a WebService in a simple way


Steps to write a Web Service :


1. Write the business implementation class under a package.


HelloWorld.java


package news;


public final class HelloWorld


{


public String sayHello(String s)


{


System.out.println("HelloWorld from your WebService");


System.out.println("This message brought to you by " + s);


return "Hello " + s;


}


}



2. compile the file

eg : javac –classpath . HelloWorld.java –d .


3. save the following build.xml file under the current working folder build.xml


targetNamespace="http://localhost/webservices/hello"


serviceName="HelloWorld"


serviceURI="/HelloWorld"


generateTypes="True"


expandMethods="True">


4. set the classpath as per the following command

set classpath=%classpath%;c:\bea\jdk141_03\lib\tools.jar;c:\bea\weblogic81\server\lib\weblogic.jar;c:\bea\weblogic81\server\lib\weblogic_sp.jar;c:\bea\weblogic81\server\lib\webservicesclient.jar;c:\bea\weblogic81\server\lib\webservices.jar;


5. Run the ant tool to generate an HelloWorld.ear file

eg: java -classpath .;%classpath% org.apache.tools.ant.Main


6. Deploy the ear file with the application server through console application


7. Write the client application


Client.java


import news.*;




public class Client


{


public static void main(String[] args) throws Exception


{


String service_url =


"http://localhost:7001/webservices/HelloWorld?WSDL";


System.out.println(service_url);


HelloWorld_Impl h = new HelloWorld_Impl(service_url);


HelloWorldPort port =


h.getHelloWorldPort();


String result = port.sayHello(args[0]);


System.out.println(result);


}


}


8. Save the following build.xml file under the same folder where the client app is existing

packageName="news"


clientJar="myclient.jar">


9. Run the following ant command to generate myclient.jar file

eg: java -classpath .;%classpath% org.apache.tools.ant.Main


10. Compile the client application by keeping the myclient.jar file in the classpath

javac -classpath .;myclient.jar;%classpath% Client.java


11. Run the client application to test the web service

java -classpath .;myclient.jar;%classpath% Client John

Popular Posts