Search This Blog

Showing posts with label ANT. Show all posts
Showing posts with label ANT. Show all posts

Friday, 18 December 2009

Starting A Coherence Cache Server from ANT

Started setting up some coherence demos through ant, in doing so created a small template to work from which enables me to start a coherence cache server. With this you simply place your source code within the SRC directory and it will compile it, package it (once we add a package task), and run the cache server.

1. Firstly create a directory as follows , adding the files (build.properties, build.xml) and 2 directories (src, lib) as shown below.

Directory Name - start-cache-server

build.properties
build.xml
classes - DIRECTORY
lib - DIRECTORY
src - DIRECTORY

2. Ensure you have ant in your path.

D:\jdev\ant-demos\coherence\start-cache-server>ant -version
Apache Ant version 1.7.0 compiled on December 13 2006

3. Edit build.properties ensuring we set coherence home correctly

# oracle.coherence.home
#
oracle.coherence.home=D:/jdev/coherence/352/coherence

# jvmargs
#
# JVM args to pass into the command at runtime to set heap size etc

jvmargs=-server -showversion -Xms512m -Xmx512m

4. Edit build.xml to look as follows
<?xml version="1.0" encoding="windows-1252" ?>

<project default="run-default" name="demo" basedir=".">

<property file="build.properties"/>

<path id="j2ee.classpath">
<pathelement path="${oracle.coherence.home}/lib/coherence.jar"/>
</path>

<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
<property name="lib.dir" value="lib"/>
<property name="class.name" value="com.tangosol.net.DefaultCacheServer"/>
<property name="jmxclass.name" value="com.tangosol.net.management.MBeanConnector"/>

<target name="init">
<tstamp/>
<mkdir dir="${classes.dir}"/>
</target>

<target name="clean" description="Clean lib, classes directories">
<delete dir="${classes.dir}"/>
</target>

<target name="compile" description="Compiles classes into ${classes.dir}" depends="init">
<javac srcdir="${src.dir}"
debug="true"
destdir="${classes.dir}"
includes="**/*.java" >
<classpath refid="j2ee.classpath"/>
</javac>
</target>

<target name="run-default" depends="compile" description="Run the cache server">
<echo message="Starting cache server with jvm args : ${jvmargs}"/>
<java classname="${class.name}" fork="true">
<!--
Add system properties as follows
<sysproperty key="tangosol.pof.enabled" value="true"/>
-->

<jvmarg line="${jvmargs}"/>
<classpath>
<path refid="j2ee.classpath"/>
</classpath>
</java>
</target>

<target name="run-jmx" depends="compile" description="Run the JMX enabled cache server">
<echo message="Starting JMX enabled cache server with jvm args : ${jvmargs}"/>
<java classname="${jmxclass.name}" fork="true">
<sysproperty key="tangosol.coherence.management" value="all"/>
<sysproperty key="tangosol.coherence.management.remote" value="true"/>
<sysproperty key="com.sun.management.jmxremote" value="true"/>
<jvmarg line="${jvmargs}"/>
<arg line="-rmi" />
<classpath>
<path refid="j2ee.classpath"/>
</classpath>
</java>
</target>

</project>
5. Run cache server using the ant task shown below.

D:\jdev\ant-demos\coherence\start-cache-server>ant run-default
Buildfile: build.xml

init:
[mkdir] Created dir: D:\jdev\ant-demos\coherence\start-cache-server\classes

compile:

run-default:
[echo] Starting cache server with jvm args : -server -showversion -Xms512m -Xmx512m
[java] java version "1.6.0_07"
[java] Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
[java] Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)
[java] 2009-12-18 10:15:15.062/0.406 Oracle Coherence 3.5.2/463 (thread=main, member=n/a): Loaded operational configur
ation from resource "jar:file:/D:/jdev/coherence/352/coherence/lib/coherence.jar!/tangosol-coherence.xml"
[java] 2009-12-18 10:15:15.078/0.422 Oracle Coherence 3.5.2/463 (thread=main, member=n/a): Loaded operational override
s from resource "jar:file:/D:/jdev/coherence/352/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
[java] 2009-12-18 10:15:15.078/0.422 Oracle Coherence 3.5.2/463 (thread=main, member=n/a): Optional configuration overri
de "/tangosol-coherence-override.xml" is not specified
[java] 2009-12-18 10:15:15.093/0.437 Oracle Coherence 3.5.2/463 (thread=main, member=n/a): Optional configuration overri
de "/custom-mbeans.xml" is not specified
[java]
[java] Oracle Coherence Version 3.5.2/463
[java] Grid Edition: Development mode
[java] Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
[java]
[java] 2009-12-18 10:15:15.531/0.875 Oracle Coherence GE 3.5.2/463 (thread=main, member=n/a): Loaded cache configurati
on from "jar:file:/D:/jdev/coherence/352/coherence/lib/coherence.jar!/coherence-cache-config.xml"
[java] 2009-12-18 10:15:16.265/1.609 Oracle Coherence GE 3.5.2/463 (thread=Cluster, member=n/a): Service Cluster joined
the cluster with senior service member n/a
[java] 2009-12-18 10:15:19.515/4.859 Oracle Coherence GE 3.5.2/463 (thread=Cluster, member=n/a): Created a new cluster
"cluster:0xD3FB" with Member(Id=1, Timestamp=2009-12-18 10:15:16.031, Address=10.187.80.135:8088, MachineId=57735, Location=site:
au.oracle.com,machine:papicell-au,process:3708, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, CpuCount=2, SocketCo
unt=1) UID=0x0ABB5087000001259EEC7BBFE1871F98
[java] 2009-12-18 10:15:19.546/4.890 Oracle Coherence GE 3.5.2/463 (thread=Invocation:Management, member=1): Service Man
agement joined the cluster with senior service member 1
[java] 2009-12-18 10:15:19.875/5.219 Oracle Coherence GE 3.5.2/463 (thread=DistributedCache, member=1): Service Distribu
tedCache joined the cluster with senior service member 1
[java] 2009-12-18 10:15:19.953/5.297 Oracle Coherence GE 3.5.2/463 (thread=ReplicatedCache, member=1): Service Replicate
dCache joined the cluster with senior service member 1
[java] 2009-12-18 10:15:19.953/5.297 Oracle Coherence GE 3.5.2/463 (thread=OptimisticCache, member=1): Service Optimisti
cCache joined the cluster with senior service member 1
[java] 2009-12-18 10:15:19.968/5.312 Oracle Coherence GE 3.5.2/463 (thread=Invocation:InvocationService, member=1): Serv
ice InvocationService joined the cluster with senior service member 1
[java] 2009-12-18 10:15:19.968/5.312 Oracle Coherence GE 3.5.2/463 (thread=main, member=1): Started DefaultCacheServer
...
[java]
[java] SafeCluster: Name=cluster:0xD3FB
[java]
[java] Group{Address=224.3.5.2, Port=35463, TTL=4}
[java]
[java] MasterMemberSet
[java] (
[java] ThisMember=Member(Id=1, Timestamp=2009-12-18 10:15:16.031, Address=10.187.80.135:8088, MachineId=57735, Location=sit
e:au.oracle.com,machine:papicell-au,process:3708, Role=CoherenceServer)
[java] OldestMember=Member(Id=1, Timestamp=2009-12-18 10:15:16.031, Address=10.187.80.135:8088, MachineId=57735, Location=s
ite:au.oracle.com,machine:papicell-au,process:3708, Role=CoherenceServer)
[java] ActualMemberSet=MemberSet(Size=1, BitSetCount=2
[java] Member(Id=1, Timestamp=2009-12-18 10:15:16.031, Address=10.187.80.135:8088, MachineId=57735, Location=site:au.orac
le.com,machine:papicell-au,process:3708, Role=CoherenceServer)
[java] )
[java] RecycleMillis=120000
[java] RecycleSet=MemberSet(Size=0, BitSetCount=0
[java] )
[java] )
[java]
[java] Services
[java] (
[java] TcpRing{TcpSocketAccepter{State=STATE_OPEN, ServerSocket=10.187.80.135:8088}, Connections=[]}
[java] ClusterService{Name=Cluster, State=(SERVICE_STARTED, STATE_JOINED), Id=0, Version=3.5, OldestMemberId=1}
[java] InvocationService{Name=Management, State=(SERVICE_STARTED), Id=1, Version=3.1, OldestMemberId=1}
[java] DistributedCache{Name=DistributedCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=257, BackupCou
nt=1, AssignedPartitions=257, BackupPartitions=0}
[java] ReplicatedCache{Name=ReplicatedCache, State=(SERVICE_STARTED), Id=3, Version=3.0, OldestMemberId=1}
[java] Optimistic{Name=OptimisticCache, State=(SERVICE_STARTED), Id=4, Version=3.0, OldestMemberId=1}
[java] InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=5, Version=3.1, OldestMemberId=1}
[java] )
[java]

Few things to note here.

- We don't have anything in the SRC directory we simply add code we wish to use in our cache server here, like cahe store implementations etc.

- When you do have SRC to compile you will need to add a package task as shown below for example.

<target name="package"
depends="compile"
description="Package application into ${ant.project.name}.jar">
<jar basedir="${classes.dir}" destfile="${lib.dir}/${ant.project.name}.jar">
<include name="**/*.class"/>
</jar>
</target>

From the build.xml there is also a target to start a JMX enabled node using "ant run-jmx"

Thursday, 8 November 2007

Using Oracle Ant Tasks within JDeveloper 10g

With OAS 10.1.3.x they released a set of Ant tasks that enable operations such as application deployment, resource configuration and server lifecycle tasks to be performed. I normally run these from the command line but recently needed to set this up in JDeveloper 10.1.3.2, his how I did that.

1. Firstly I decided to use this 10.1.3.x how to on the OTN web site

http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html
How-To Swap XML Parsers ( zip ) Aug-2006

I downloaded the ZIP file onto my file system so I could set this up in Jdeveloper. The 3 files I need are as follows.
  • ant-oracle.properties
  • ant-oracle.xml
  • build.xml
2. In JDeveloper create a new empty project within a workspace
3. From the Object gallery add a new empty build.xml file
4. Copy the 3 files above into the same directory the build.xml was added to in JDeveloper. Basically you are replacing the empty build.xml and adding the 2 other files needed for oracle ant tasks.
5. Use the Refresh icon on the application navigator to ensure all 3 files appear in the project as shown below.




6. Now we need to configure the ant-oracle.properties file to specify our deployment server settings. I am deploying to a OAS 10.1.3.2 instance named pas_oc4j. That said his the settings I am using , thats pretty much all you need to set in that file.

oracleas.host=papicell-linux.au.oracle.com
oracleas.http.port=7779
oracleas.admin.port=6007
oracleas.admin.user=oc4jadmin
oracleas.admin.password=welcome1
oracleas.binding.module=default-web-site
oracleas.deployer.uri=deployer:oc4j:opmn://${oracleas.host}:${oracleas.admin.port}/${oracleas.oc4j.instance}
oracleas.oc4j.instance=pas_oc4j

7. Now we have an empty project , but in order to use this otn how to we need to add a JSP to the project, a library and a few deployment descriptor XML files.
8. Add the library "Oracle XML Parser v2" to the project using the Project Properties dialog
9. Add a new JSP file called "index.jsp" using the new object gallery, I placed it in a folder named "web".

What you will find is a web.xml is created automatically for you once the JSP was created in the public_html\WEB-INF directory. All we need to do now is copy the files below from the downloaded how to ZIP into that directory on the file system and press Refresh to show the files in the JDeveloper project
  • orion-application.xml
  • application.xml
10. Now we are ready to deploy using ant BUT before we do that we need to alter the build.xml as the file downloaded from OTN is setup based on the ZIP file, but in JDeveloper we have a slightly different directory structure so in the build.xml we need to alter the "init" target so it looks as follows which matches our directory structure in the project


<target name="init" depends="common">

<echo message="-----> Initializing project properties"/>

<property name="app.name" value="how-to-swapxmlparser"/>

<property name="ear.name" value="${app.name}"/>

<property name="web.name" value="${ear.name}-web"/>

<property name="src.dir" value="./public_html"/>

<property name="bld.dir" value="./build"/>

<property name="lib.dir" value="D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy/lib"/>

<property name="etc.dir" value="./public_html/WEB-INF"/>

<property name="log.dir" value="./log"/>

<property name="src.web.dir" value="${src.dir}/web"/>

<property name="bld.web.dir" value="${bld.dir}/${web.name}"/>

<property name="bld.ear.dir" value="${bld.dir}/${ear.name}"/>

<property name="bld.compiler" value="classic"/>

<property name="class.files" value="**/*.class"/>

<property name="bak.files" value="**/*~"/>

</target>



11. You will see I hard coded the full path to the final EAR file we will deploy due to an issue with JDeveloper which once I sort it out I will update this blog with a more elegant way of referring to that file. For now simple replace the full path with your directory structure ensuring "lib" remains as ant script is using the "lib" directory.

D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy/lib

12. Right click on build.xml and select -> Run Ant and select the target all

Output as follows

Buildfile: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy\build.xml

common:
[echo] BuildName: how-to-swapxmlparser
[echo] BuildHome: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy
[echo] BuildFile: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy\build.xml
[echo] BuildJVM: 1.5

init:
[echo] -----> Initializing project properties

setup:
[echo] -----> Creating the required sub-directories

package-web:

package-app:

checkoc4javailable:
[echo] ------> Checking to see if OC4J is available to deploy to
[echo] Pinging papicell-au2.au.oracle.com:6007
[echo] If OC4J is not started, please start it now.

skipdeploy:

deploy-ear:
[echo] -----> Deploying the application module deployment (ear) file
[echo] Target: deployer:oc4j:opmn://papicell-au2.au.oracle.com:6007/pas_oc4j
[echo] lib.dir: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy/lib/how-to-swapxmlparser.ear
[oracle:deploy] Deploying application how-to-swapxmlparser.
[oracle:deploy] Application deployer for how-to-swapxmlparser COMPLETES.

deploy:
[echo] -----> Deployed the application components required by OC4J for the execution of this application

all:
[echo] -----> Created all deployable units for the application

BUILD SUCCESSFUL
Total time: 4 seconds


So after a little tweaking we can easily get the OC4J OTN 10.1.3.x how-to's incorporated into JDeveloper using Oracle Ant Tasks to do our compilation/deployment for us.