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

Thursday, October 29, 2015

I want the app to be flexible enough during run-time

In Eclipse IDE, the simplest way to configure class-path is to create a source folder. It is so clean and easy. But when using ANT to package a JAR, class-path is done in the following way:
<project ...>
   <target name="build">
      <jar destfile="./program.jar">
         <manifest>
            < attribute name="Main-Class" value="..."/>
            < attribute name="Class-Path" value="..."/>
         </manifest>
      </jar>
   </target>
</project>
Usually class-path is useful in referencing the library path. But I never though it can be use to reference configuration file, the file which usually in XML or properties pattern. Assuming configuration files were located at config_path, the class-path would be look like this:
<project ...>
   <target name="build">
      <jar destfile="./program.jar">
         <manifest>
            < attribute name="Main-Class" value="..."/>
            < attribute name="Class-Path" value="config_path/ lib_path/the.jar ..."/>
         </manifest>
      </jar>
   </target>
</project>
With this approach, I can have a greater flexibility to configure the application's behavior in anytime during run-time.

Friday, July 31, 2015

SVN copy task causing duplicate path?

There is a problem with the <copy> task after deployed to build server. The path will become duplicate when it is executing causing the path, unable to be retrieve:
   ...

   [svn] svn: File not found: revision 1768, path '/trunk/MessageFlow/trunk/MessageFlow'

   ...
Notice that the path has been duplicated. Here is the existing ANT source:
   ...
   <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="classpath"/>

   ...

   
      <copy srcUrl="${svnTrunkRoot}/MessageFlow}" destUrl="${svnTagsRoot}/MessageFlow/${newtagname}" message="Tagged by Jenkins."/>
   
As from my study, this is a known error for SVN version 1.7 and above. Luckily opticyclic has developed a new ANT clone which can get rid of this problem. Grab the piece and build it from source. The output will have this, svntask-1.1.1.jar. When deploy to build server, sequence-library-1.0.2.jar, sqljet-1.1.10.jar, svnkit-1.8.5.jar are also needed. There are gang of four, no one left behind.

Without messing up with the existing svn task, I create another task named svn2.
   <path id="svn2.classpath">
      <pathelement location="svntask-1.1.1.jar">
      <fileset dir= "../lib">
         <include name= "*.jar"/>
      </fileset>
   </path>

   <taskdef name="svn2" classname="com.googlecode.svntask.SvnTask" classpathref="svn2.classpath"/>
To use the new copy task command, do this:
   ...
   <svn2 username="admin" password="admin">
      <copy failOnDstExists="true" move="false"
            src="${svnTrunkRoot}/MessageFlow"
            dst="${svnTagsRoot}/MessageFlow/${newtagname}"
            commitMessage="Tagged by Jenkins."/>
   </svn2>
Do take note that the new svn2 doesn't support refid attribute, thus username and password are require whenever svn2 command is invoke.

Last note, this is last minute finding, antlr-runtime-3.4.jar may also needed as I deployed to build server. Otherwise an run-time error will be thrown.

Checking SVN path existence using ANT

The use case here was to check whether the path has already existed in SVN using ANT. I was staring on the script (shown below) for a very long time and wondering how could I improve the piece to make it more interesting and sexy.
   <if>
      <svnExists target="${svnPath}/MessageFlow/${tagname}" refid="svn.settings"/>
      <then>
         ...
      </then>
   </if>

   <if>
      <not><svnExists target="${svnPath}/MessageFlow/${tagname}" refid="svn.settings"/></not>
      <then>
         ...
      </then>
   </if>
After some rearrangement then I come out this piece:
   <condition property="exists">
      <svnExists target="${ svnPath}/MessageFlow/${tagname}" refid="svn.settings"/>
   </condition>

   <!—if exists is false -->
   <if>
      <not><equals arg1="${exists}" arg2="true"/></not>
      <then>
         ...
      </then>
   </if>

   <!—if exists is true -->
   <if>
      <equals arg1="${exists}" arg2="true"/>
      <then>
         ...
      </then>
   </if>
The difference on the newer piece is that I've adopted <condition> in the script and the result was keep in exists property. Would it be better? Errrrr... It seems that a lot more code need to be done to achieve the same result.

Monday, July 20, 2015

Cannot use javahl nor command line svn client

I do not know since when the 3 idiots svnant.jar, svnClientAdapter.jar, svnjavahl.jar was placed inside ANT_ROOT/lib? I'm feeling so unhappy with this as it has caused me a nasty shit being thrown when <svn> tag was invoked!
    Trying to override old definition of task svn
    
    BUILD FAILED
    ...
    C:\TestWorkspace\base.xml:78: Cannot use javahl nor command line svn client
    
    Total time: 0 seconds
When I was about to throw them away, I notice the last modified date was at 2006 which is version 1.0.0 as according to the source repo. Surprise me! But I thought I had overridden the classpath in ANT script, why it isn’t working?
    <path id="classpath">
     <pathelement location="svnant.jar"/>
     <pathelement location="svnClientAdapter.jar"/>
     <pathelement location="svnjavahl.jar"/>
     <pathelement location="svnkit.jar"/>
     <pathelement location="ant-contrib-0.3.jar"/>
     <fileset dir= ".." >
      <include name= "*.jar" />
     </fileset>
    </path>
I rebuild again to see if the error still persists after I throw the 3 idiots far far far away. The error is gone but another one comes out:
    co:
          [svn] Missing 'javahl' dependencies on the classpath !
    
    BUILD FAILED
    ...
    C:\TestWorkspace\base.xml:80: Cannot find javahl, svnkit nor command line svn client
Surprise me again! Why this happens? Spent some time reading through the forums and articles then only I realize there are missing thing in the ANT script:
    <svnSetting svnkit="true" javahl="false" username="admin" password="admin" id="svn.settings" />
    <svn refid="svn.settings">
     ...
    </svn>
Frankly speaking, I heavily rely on the IDE. The <svn> tag wasn’t shown in editor, and I though this is a fault. Anyhow, one quick note, as of this writing, I’m using version 1.3.1. Thus svntask.properties is no longer working:

    <typedef classpathref="classpath" resource="svntask.properties"/>

That one was used in version 1.0.0. The correct way is this:

    <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="classpath"/>

Wednesday, July 3, 2013

ANT unable to change JDK path

ANT is depends on JAVA_HOME environment variable to determined which JDK version should be use during compilation. Somehow my situation was even though I have update from existing JDK1.5 JAVA_HOME to a new JDK1.6 JAVA_HOME, ANT still using JDK1.5 during the compilation.

Until I found out there is a better way to configure JAVA_HOME for ANT in Eclipse rather than configure it through environment variable, which is, in Eclipse IDE > Run Menu > External Tools Configuration > JRE tab > choose Run in same JRE as workspace option. I choose this option because whenever I change the compiler in the project, the ANT compiler will change accordingly.

Thursday, June 20, 2013

How to copy a folder with Ant JAR task?

When packaging a Jar using ANT, usually I’ll just don’t care the file structure and dump whatever thing into root directory of a package. The code below showing you a clear picture on how the real thing works:
<jar basedir="build/classes" destfile="${lib.dir}/MyPackage.jar">
    <fileset dir="${lib.dir}">
          <include name="*.jar">
    </fileset>
    
    ... 
But somehow there is a situation where the requirement from my superior was so stubborn that I have to follow the existing file structure as in the development. Meaning that all libraries must locate inside lib folder. Fortunately nothing much change in the build.xml, see the code:
    <jar basedir="build/classes" destfile="${lib.dir}/MyPackage.jar">
       <fileset dir=".">
          <include name="${lib.dir}/*.jar">
       </fileset>