Top posts

Latest articles


Starting a new project: UML designer

Posted by Jongerius under Development
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (No Ratings Yet)
Loading ... Loading ...

In my line of work it is required to create a UML diagram every now and then. The problem with that is that there are no good free tools available any more that allow you to do so. There used to be a tool called StarUML, which is really good. Unfortunately it is no longer supported nor being developed.

In the forums of StarUML there was a lot of chatter about setting up a new group to continue where StarUML left off. But I’ve not been able to find any progress on that at all, after 3 years or so. So I took it upon myself to start building my own tool to design UML diagrams, which is a rather big project. Probably the biggest I’ve set out to do so far. At the moment I’m sorta at the stage of designing some basic user interface for the tool (basic prototype only). Once that is done I will look into how to setup the program and start the happy coding :-) .

The idea is to do all the development in a combination of C++.NET as well as some older C++ libraries that I already created in the past. After I’m done the program will be released as a freeware application with limited support.

It will probably be a long time before I can release anything useful to the public, as I’m doing this in my spare time. If you are interested then give me a message and I’ll try and keep you updated. If you have some useful ideas then please sent them to me. I’d love any feedback about it.


Controlling Tomcat using Ant scripting

Posted by Jongerius under Internet, Webdevelopment
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (No Ratings Yet)
Loading ... Loading ...

As a Java webdeveloper you are faced with a lot of different aspects of development. One is testing and debugging code, to do this you need an application server like Tomcat. One of the issues I recently encountered was the need to control various Tomcat instances with a single Ant build script. Below are some of the solutions I’ve used to manipulate Tomcat.

Note: some parts of this script rely on the ant-contrib library. Download this library and include it in the tomcat.xml with the following code:

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
 <classpath>
  <pathelement location="./ant-contrib-1.0b3.jar"/>
 </classpath>
</taskdef>

Starting tomcat

Though starting tomcat may seem easy. You could just use the development IDE (like Netbeans) to start and stop Tomcat, but what this lacks is the ability to control several instances with easy shortcuts. So I defined the following Ant macrodef in a file called tomcat.xml:

<macrodef name="tomcat-start">
 <sequential>
   <trycatch>
    <try>
      <if>
       <not><http url="http://localhost"/></not>
       <then>
         <java classname="org.apache.catalina.startup.Bootstrap"
             fork="yes"
             dir="${tomcat.dir}"
             spawn="true"
             jvm="${tomcat.java.home}/bin/java">
          <jvmarg value="-Dcatalina.home=${tomcat.dir}"/>
          <jvmarg value="-Dcatalina.base=${tomcat.dir}"/>
          <jvmarg value="-Djava.io.tmpdir=${tomcat.dir}/temp"/>
          <jvmarg value="-Djava.endorsed.dirs=${tomcat.dir}/common/endorsed"/>
          <jvmarg value="-Xdebug"/>
          <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"/>
          <classpath>
           <pathelement location="${tomcat.java.home}/lib/tools.jar"/>
           <pathelement location="${tomcat.dir}/bin/bootstrap.jar"/>
          </classpath>

          <arg line="start" />
         </java>

         <waitfor maxwait="10" maxwaitunit="second" checkevery="5000">
          <http url="http://localhost"/>
         </waitfor>
         <echo message="Tomcat started"/>
       </then>
       <else>
        <echo message="Tomcat already started..." />
       </else>
     </if>
    </try>
    <catch>
     <echo message="Unable to start tomcat"/>
    </catch>
  </trycatch>
 </sequential>
</macrodef>

This macro is really easy. First it starts of by checking if tomcat is not already running (well actually it just checks to see if there is something running on port 80). If nothing is running then tomcat is started using the java defined by the ant property tomcat.java.home. This macro also depends on some other properties that are set by a different macro, which will be a bit further on in the post. Tomcat is started by using the Bootloader class provided by the server, to make sure it loads correctly the classpath is set.

The last step in the macro is to wait for tomcat to start, this has to be done since we start tomcat in a seperate java instance (the spawn option).

Stopping Tomat

Off course you also want to be able to stop tomcat to load some new data, or an entire web-app. I use the following macro to stop Tomcat:

<macrodef name="tomcat-stop">
 <sequential>
  <trycatch>
   <try>
    <java classname="org.apache.catalina.startup.Bootstrap"
         fork="yes"
         dir="${tomcat.dir}"
         spawn="true"
         jvm="${java.home}/bin/java">
     <jvmarg value="-Dcatalina.home=${tomcat.dir}"/>
     <jvmarg value="-Dcatalina.base=${tomcat.dir}"/>
     <jvmarg value="-Djava.io.tmpdir=${tomcat.dir}/temp"/>
     <classpath>
      <pathelement location="${tomcat.java.home}/lib/tools.jar"/>
      <pathelement location="${tomcat.dir}/bin/bootstrap.jar"/>
     </classpath>

     <arg line="stop" />
    </java>

    <kill-java name="Bootstrap" />
    <echo message="Tomcat stopped" />
   </try>
   <catch>
    <echo message="Unable to stop tomcat forcing shutdown....."/>
    <kill-java name="Bootstrap" />
   </catch>
  </trycatch>
 </sequential>
</macrodef>

Just like with the starting of Tomcat I use the provided Bootloader class to instruct tomcat to stop. Again I use the java that is set in tomcat.java.home as well as some other properties loaded by another macro. Since Tomcat sometimes fails to stop gracefully (due to poorly designed webapps) you also have to kill the Java process of Tomcat. This is done with the call to kill-java.

Killing any java process

As you saw in the tomcat-stop macro I used a macro called kill-java to make sure that Tomcat is really killed and no longer running in the background. The macro is as follows:

<macrodef name="kill-java"
          description="Forcefully stop tomcat....">
 <attribute name="name"/>
 <sequential>
  <!-- Execute the jps and check for any Java process with the provided @{name} attribute -->
  <exec executable="${tomcat.java.home}/bin/jps" output="pid.out.file" />
  <!-- Load in the name / pid file and strip all information except the PID -->
  <loadfile srcfile="pid.out.file" property="pid.out">
   <filterchain>
     <linecontains>
      <contains value="@{name}"/>
     </linecontains>
    <tokenfilter>
    <deletecharacters chars="@{name}"/>
    <trim/>
    <ignoreblank/>
    </tokenfilter>
    <striplinebreaks/>
   </filterchain>
  </loadfile>
  <echo message="Killing java process with pid ${pid.out}"/>
  <!-- Kill the process, warning this only Works on Windows -->
  <exec spawn="true" executable="taskkill">
   <arg line="/PID ${pid.out}" />
   <arg line="/F" />
  </exec>
  <delete file="pid.out.file" />
 </sequential>
</macrodef>

This macro is really simple and relies on the jps application provided by Java. This application returns a list of all running processes with name and process id (PID). All we need to do is get the line containing the process name provided and strip everything except the PID.

Please note: the task killing the proces is designed for Windows, you could change this with kill in Linux.

Rounding it up

Though you now have all you need to manipulate tomcat there is one last macro that we are tegenkant upon. That is the initializer of the various Tomcat properties. I use the following macro:

<macrodef name="tomcat-init">
 <attribute name="from"/>
 <sequential>
  <property name="tomcat.dir" value="${tomcat.@{from}.dir}"/>
  <property name="tomcat.server" value="${tomcat.@{from}.server}"/>
  <property name="tomcat.port" value="${tomcat.@{from}.port}" />
  <property name="j2ee.server.type" value="${tomcat.server}" />
  <taskdef name="webapp-stop"
          classname="org.apache.catalina.ant.StopTask"
          classpath="${tomcat.dir}/server/lib/catalina-ant.jar"/>
  <taskdef name="webapp-start"
           classname="org.apache.catalina.ant.StartTask"
           classpath="${tomcat.dir}/server/lib/catalina-ant.jar"/>
 </sequential>
</macrodef>

This little macro will initialize tomcat for a specific environment (for exemple DEV). Of course none of this works without the loading of some preset properties in a property file tomcat.properties. Which contains the following data:

tomcat.java.home=C:/jdk1.5.0_22_32b

tomcat.DEV.dir=d:/jakarta/tomcat5.0
tomcat.DEV.server=tomcat55-DEV
tomcat.DEV.port=8000

tomcat.MAIN.dir=d:/jakarta/tomcat5.0-MAIN
tomcat.MAIN.server=tomcat55-MAIN
tomcat.MAIN.port=8000

To load the property file just include the following instruction in the build script:

<property file="./tomcat.properties" />

Setting up a mailserver, continued

Posted by Jongerius under Internet, Uncategorized
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (1 votes, average: 3.00 out of 6)
Loading ... Loading ...

In my last article on how to setup a basic mail server in debian using postfix and dovecot, I am now continueing on how to setup some basic spam filters. The reason to split this up, well I was stupid and assumed I wouldn’t need a spam filter yet. But I forgot that I also moved one domain to my new mail server that got 200 spam messages a day.

So now to repair my mistake I am adding the following features to my already existing mail server. To find out how to setup the  mail server itself read my earlier article.

  • Use spamassassin to mark spam in the header
  • Change the mail delivery to dovecot LDA, this is needed for step 3
  • Automatically move marked e-mails to the spam folder of the user

Sounds easy right. Well it should be ;-) .

(more…)


Upgrading my VPS to Debian Etch

Posted by Jongerius under General Rant, Internet
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (No Ratings Yet)
Loading ... Loading ...

You might have noticed it yesterday, or not ;) . But my blog and several other websites hosted by me went offline yesterday for a couple of hours. Well this had to do with me upgrading the VPS to Debian Etch.

So far I ran every website on Debian Sarge, and though it’s stable they choose to no longer developer for it nor support it. So it was time to move to a newer version. Wich I did yesterday. Here’s some of the steps you should take before upgrading to the next version of Debian.

  • Make a full backup of any website’s / databases / scripts running (don’t forget your crontab and logrotate files)
  • Copy the backup to a directory not affected by the upgrade. In my VPS the provider has one folder which will be left untouched, but also pull the backup to a local system (just in case ;) )
  • Notify any other users also using your server, don’t want any suprises to potential paying customers.

I was lucky that my hosting provider offers an easy way to upgrade or reinstall a Linux distro on the VPS. Just a couple of mouse clicks and they prepare the VPS for the installation. Please note that this will take up to an hour to complete. Once this base installation is complete you will want to perform the following steps:

  1. Un rar the backup of the websites / conf files and scripts (tar xf <tar name>) and move them to the right location.
  2. Setup the proper user account /groups to have access to these files (or your users won’t be able to upload or change the website’s any more)
  3. Install apache / PHP and mysql by running the following command:
      apt-get install php5 mysql5-server apache2 mysqllib
  4. Setup the apache conf file to load in your restored conf files (eg: Include /export/conf/apache/*.conf)
  5. Replace the mysql my.cnf with the one you backed up previously
  6. Enable the rewrite and ssl modules of apache (I forgot and got some upset calls :( )

From this point on your ready to go. All of the websites should be running without any problems. You do need to configure any other tools you had installed, like AWStats / Subversion or anything else. Though these should not require to much configuration as all of the configuration files where included in your backup. At least if you followed a setup similar to my first article on setting up linux.


Synchronizer 2.0 Beta 1

Posted by Jongerius under Development, Uncategorized
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (1 votes, average: 5.00 out of 6)
Loading ... Loading ...

A long time ago I released an early alpha version of Synchronizer. A tool that can automatically synchronize files between directories. Today it’s finally time for the first beta release. Which fixes a lot of problems people had when using the tool.

One of the first problems reported back to me was that the tool crashed whenever ran with some strange error message. Well appearantly this was caused by the .Net framework, a problem which I solved.

For a quick list of bug fixes:

  • Program no longer requires .Net framework to run, which was a big bug in the early alpha release
  • Logging is a lot more robust and stable, this actually caused some crashes in the past
  • Memory usage is way down, solved a lot of memory leaks
  • Solved a problem that for some systems directories were not created at the destination folder
  • Solved a problem causing synching to mounted network folders to fail

Of course some things have not yet been solved, but are in the works:

  • Multithreaded causes some logging problems and crashes (please be carefull with multithreading at this time)
  • If debug information is enabled the memory usage is huge on large directories, on the Windows directory it rose to 89 MB.

If you find any trouble running it or it crashes on you then let me know, and if at all possible send me the log file created by the tool using the -dd option. That will help me track down the problem.

You can download it by clicking this text.

Next Page »