Posts

Cargo-itest open source project

I recently started an open source project called cargo-itest. This was started up because when I worked on several projects I needed to create integration tests for them which all had similarities. I was previously doing it with the maven2 cargo plug-in but wasn't really fond of it because it most of the times didn't work and when it worked it stopped working after editing the configuration. In other words it was very unstable. This initiated me to start to use the java API of Cargo instead of the maven plugin. By using the java API it already removes the dependency from your build system in this case Maven. Having no dependency on the build system gives you a couple of advantages: You can run it in any IDE that supports JUnit. You can switch easily to another build system without changing your tests and test configuration. These are general advantages of just using the API but also part of using my open source project cargo-itest. This project enables you to easily start creat...

Specify context name in Tomcat

When developing web applications that are distributed as WAR files running in Tomcat most of the times you want to be able to specify the context name to a nicer name than Tomcat provides by default. Which is the name of the WAR file itself. When i.e. you are keeping the version within the name of the WAR this will result in some weird name like myapp-1.2. This is most of the times not what you want. Most of the times you want a nice context name like myapp without the version in it. According to the Tomcat documentation you can do it in 3 ways: Edit the server.xml Add a context.xml to the $CATALINA_HOME/conf/Catalina/localhost with the name of your context. Add a context.xml to your META-INF directory in your WAR file The first two options just work fine only the last one doesn't do the job for you for some reason. Personally the second option is the best option since it's not intrusive to your application and also not to Tomcat since you leave the server.xml alone. This way y...

Setup Postgres on Fedora Linux 10

Installing PostgreSQL on Fedora Linux 10 is pretty straight forward. You need to follow the following steps: #1 Initialize postgres initdb /var/lib/pgsql/data #2 Add the following line to pg_hba.conf: local all all trust #3 Switch to postgres user su postgres #4 Connect to PostgreSQL psql -d template1 #5 Change password ALTER USER postgres WITH PASSWORD 'this_is_my_password'; #6 Remove line from step 2

Enabling GZIP compression on Tomcat

Enabling GZIP compression for your web application is a good way to accelerate your web site. This can reduce the size of data being transferred and, consequently, speed your application. Enabling compression on the web server will make data be transferred in compressed form. The browser will decompress the data on the fly, making the application faster. If your application uses Ajax, what usually increases the volume of data transferred from server to client, compression of data will significantly improve your application performance. Here is how to enable GZIP compression on Tomcat: edit file /conf/server.xml and add to the HTTP Connector configuration something like this: compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml" An example of a HTTP Connector configuration with compression enabled could be: Connector port="8080...

How to install Java in Fedora Core

By default, Fedora Core 6 systems come with an old Java software installed, so you need to install a newer version of Java Runtime Environment to enjoy all the Java applications out there. In this quick guide, I will teach you how to update/install your Java Environment. Let's begin by downloading the latest version of JRE (Java Runtime Environment) from here. Just click on the Download link where it says Java Runtime Environment (JRE) 5.0 Update, then you'll need to accept the license and download the Linux self-extracting file. WARNING: Please remember to always replace the xx from the jre-1_5_0_xx-linux-i586.bin file with the latest version. At the moment of this guide's writing, the latest version was 09, so the file should look like this: jre-1_5_0_09-linux-i586.bin After you have finished downloading the file, you need to move it into the /opt folder. Open a console and type: mv jre-1_5_0_xx-linux-i586.bin /opt Now, you will need to make this file executable so yo...

Opening a PDF file in a Java Application

PDF is a very common used file format for documents so quite often you need to develop applications that work with them. In Java it's fairly easy to open a PDF document using the runtime executer. Below you find a code snippet that does the job. Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); This peace of code let's Windows deside what application to use to open the PDF file which is quite cool since most of the time you don't know what application users use to open PDF files. :-)

Remotely debugging JBoss

When working with JBoss sometimes it's needed to debug your code while running instead of running your application in a lightweight servlet container like Jetty or Tomcat. This can be done by adding the following line to your run.bat or run.sh: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 You need to add this to your JAVA_OPTS variable so it will be used when JBoss starts up. When starting up now you can attach a debugger i.e. in Eclipse to the port you specified. :-)