Tampilkan postingan dengan label Ant. Tampilkan semua postingan
Tampilkan postingan dengan label Ant. Tampilkan semua postingan

Ant Tasks for Websphere Deployment

The following is my ant for websphere deployment, application start & stop, etc. The complete API doc can be found in IBM website: https://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.wsps.602.javadoc.doc/doc/index.html
For this tasks to run, you need to have the jar file com.ibm.ws.runtime.jar. This jar file can be found in plugins directory of your Websphere installation.

<property name="hostName" value="localhost" />
<property name="connType" value="SOAP" />
<property name="port" value="8880" />
<property name="deployEar.dir" value="C:\Users\firmanw\Documents\zw2\OSMS\build" />
<property name="deployEar" value="osms.war" />
<property name="wasHome.dir" value="C:\Program Files (x86)\IBM\TeamConcert\runtimes\base_v7" />
<property name="app.name" value="osms_war" />
<property name="profile.name" value="profilexfirman" />
<taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication" classpath="com.ibm.ws.runtime.jar" />
<taskdef name="wsStartApplication" classname="com.ibm.websphere.ant.tasks.StartApplication" classpath="com.ibm.ws.runtime.jar" />
<taskdef name="wsStopApplication" classname="com.ibm.websphere.ant.tasks.StopApplication" classpath="com.ibm.ws.runtime.jar" />
<target name="installEar" depends="build.osms">
<echo message="Deployable EAR File found at: ${deployEar.dir}/${deployEar}" />
<wsInstallApp ear="${deployEar.dir}/${deployEar}" wasHome="${wasHome.dir}" conntype="${connType}" port="${port}" host="${hostName}" profilename="profilexfirman" options="-appname ${app.name} -usedefaultbindings -update" />
</target>
<target name="startInstallEar" depends="installEar">
<echo message="Mulai ngestart" />
<wsStartApplication wasHome="${wasHome.dir}" conntype="${connType}" port="${port}" host="${hostName}" profilename="${profile.name}" application="${app.name}" />
</target>
<target name="startEar">
<echo message="Mulai ngestart" />
<wsStartApplication wasHome="${wasHome.dir}" conntype="${connType}" port="${port}" host="${hostName}" profilename="${profile.name}" application="${app.name}" />
</target>
<target name="stopEar">
<echo message="Mulai nyetop" />
<wsStopApplication wasHome="${wasHome.dir}" conntype="${connType}" port="${port}" host="${hostName}" profilename="${profile.name}" application="${app.name}" />
</target>

<target name="restartEar" depends="stopEar, startEar"></target>

Websphere hot deployment and dynamic reloading

In the office we use Websphere AS and RAD as IDE. When you make changes to a Java class file, the changes are publised by the IDE to the AS, and the server restarts for the changes to take effect. This is in contrast to the changes done to JSP which do not require server restart to take effect. Actually there is a possibility of hot deployment and dynamic reloading (http://publib.boulder.ibm.com/infocenter/wsdoc400/v6r0/index.jsp?topic=/com.ibm.websphere.iseries.doc/info/ae/ae/trun_app_hotupgrade.html) which basically works like this: you replace the class file in the server with the new class file and the changes should take effect immediately without needing server restart. This is a very useful feature of WAS and it makes me wonder why the WAS plugin for RAD/Eclipse does not have a feature to enable this. I know there are limitations, like when you replace Hibernate entities or deployment descriptor, then you still need to restart the server but generally this feature is very useful during development.

So i decided to write an ant build file which runs when there is an automatic build. The job of this build file is basically to replace the class files in the server with the newly built class files in the workspace.

To do this, I first need to manually deploy the EAR via the WAS console. This is to make the exploded EAR file available in the server. Because when i deploy the ear by right clicking on the project -> run as -> run in the server, the exploded ear file is not there in the server! I dont know where, probably in one of the numerous plugin directories of the RAD/Eclipse installation.

After the ear file is manually deployed, then disable automatic publishing in the WAS plugin.


And then the ant build file:



Pretty obvious I guess. The src.osms is the workspace build directory while the des.osms is the WAS exploded ear directory. The most important part of the build file is the mnodified selector (https://ant.apache.org/manual/Types/selectors.html#modified) which selects only recently modified file (which is the file newly built by Eclipse automatic build) and copies these files to WAS.

Now, this ant build file needs to run everytime you modify a class file or anything, so enable automatic build on your project.

And then right click on your project -> properties -> builders -> new -> ant builders -> OK. You get this dialog
Choose your ant build file. Then click on the target tab and set the target for manual build and auto build. Done.


PS: if you have money, try JRebel.

Wrong Java version

So the situation is like this: We have an application that relies on a jar file. This jar file is our customization to the W3C flute project. Let's call this jar flute1.jar. Our app has a bug that necessitates fiddling with flute1.jar.

So I located the bug. I rebuilt the flute1 project. I installed the newly built flute1.jar into our app. And then I committed the newly built jar (replacing the old jar) into the svn repo.

Our Hudson threw this message:

    [javac] bad class
    [javac] class file has wrong version 50.0, should be 48.0
    [javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
    [javac] import org.w3c.flute.parser.Parser;
    [javac]                             ^
    [javac] 1 error





What has gone wrong? It turned out that I built the flute1.jar to conform to Java 1.5 while our app conformed to Java 1.4 only. So I added the target="1.4" switch to the javac task in my ant build file. And it worked.

"Run as -> Ant build" disappear from pop up menu!

So.... this is weird. And inconvenient too. I was working on my Eclipse Helios and as I right click on my build.xml file, the "Run as -> Ant build" disappear from pop up menu! The cure is simple: Restart eclipse! But it caused some nerve at first because I had thought something went wrong and I had to do a lot of work to get it back to normal function.

New Eclipse. New Problems.

I got bored of my Eclipse Galileo for PHP. I no longer developed PHP and I used it to develop Java app, so I installed Java EE dev plugin and I thought it made the Galileo got rather bloated. I decided to download afresh Eclipse Helios for Java EE. I unzipped it and clicked the eclipse executable binary. Problems soon followed as I opened the projects I had previously worked on with my Eclipse Galileo.

  1. I no longer can connect to the SVN.
  2. I lost all of my run and debug configurations.
  3. Word completion does not work.
  4. I usually only needed to right click on a Java applet source code or Java code containing main class and choose run, and they ran, now I longer could do that.
I'll talk about all 4 points one by one. 

It turns out that Eclipse out of the box does not have Subversion (which is Eclipse plugin for SVN) installed. This is because installing Subversion is a 2 steps process: First you need to install Subversion plugin, which is provided by Eclipse, and then you have to install a separate connector which is provided by Polarion and not included in Eclipse due to licensing issue.

When I first tried to install Subversion, I did a stupid thing. I added subversion.tigris.org into the update address and then I installed the plugin provided by that address. After being installed, the plugin could not connect to SVN. The correct thing to install Subversion is as follows:
  1. Check for Helios update. Locate the "Collaboration" option. Install "SVN Team provider".
  2. After it is installed, try to connect to SVN repository or do something else SVN related. You will then be prompted to install Subversion connector from Polarion. Choose the latest SVNKit instead of the JavaHL option.
  3. Done!
Now you have "Team" menu when you right click on any Java file. 

But then on the 'Team" menu, I could not find "Update", "Synchronize" or "Commit" option as usual. It seemed that my newly installed Eclipse Helios did not recognize the SVN directories that were created by my previous Eclipse installation. I again did a stupid thing: I deleted all project on my disk and checked out all projects anew. 

I could have saved a lot of time by clicking "Team" and then "Share" instead. That would make my new Eclipse recognize the old SVN directories.

After I checked out all projects, I ran into new problems. I could not manipulate the source files like usual. The word completion did not work. It turns out that newly checked out projects are not recognized by Eclipse as Java project, that is why word completions do not work. So I had to delete the projects from workspace (but not from disk!) and then reopened them as Java projects.

One more tidbit, my projects came with Ant build files. I ran the ant. Failed. I fixed my project setting. I ran the ant. Successful. I tried to right click on my source file containing main class and chose run as Java application. Failed. It turns out I had to compile the project using Eclipse built in compiler in order to enable me to do that. So I cleaned the project (Project -> Clean) and then I could right click and run it. By the way, the option "Build automatically" in the Project menu means that the build will be executed automatically right after you clean the project.

Enabling Ant, Searching for file containing certain text in Linux, Eclipse fails to run after crashing

I was importing project into Eclipse when I saw that there was no ant icon on .xml file. When I right click the build.xml, there was no option to run it as ant build. The solution is simple: just install Java EE Developer Tools Component.

I often need to search for files containing certain text in Linux. The following command does the magic:
grep -lir 'the text to be found' ./
I installed Eclipse PDT (Eclipse for PHP projects) and I tried to open a file with embedded applet. Eclipse crashed right away. After the crash, there was no way for me to start Eclipse again. After some searches, I stumbled upon this blog. I deleted the content of the .settings directory as explained in the blog, but Eclipse still failed to start. Then  Jason told me to remove user properties files. They could be found on the directory .metadata. This directory itself was located in the workspace directory. After I did that, Eclipse started, but I lost all of my workbench configurations and I had to redo all of the config. But it was better than not having Eclipse start at all. At least I learnt something new.