Friday, December 23, 2011

Creating Windows Shortcuts for Java Applications

I recently started reading about implementing Selenium Server into my testing process. I quickly downloaded the jar file from their website and opened up my cmd.exe application. While I used the following process for starting Selenium Server, some minor modifications can allow you to shortcut start your programs.

I wanted to create a shortcut icon to start Selenium Server to save me a couple of steps.

Windows allows easy creation of shortcuts by finding the application, right-clicking, choose Send To => Desktop (create shortcut).

To start, I used this step to create a shortcut to cmd.exe. I used the Start Menu Application Search to easily locate cmd.exe. Once listed, I right-clicked, and created a shortcut on the desktop.

Now I right-click the shortcut and choose Properties. This opens a window that allows me to customize what my shortcut is going to do.

Under the Shortcut Tab, I altered the Target field to read:

C:\Windows\System32\cmd.exe /k java -jar C:\dev\tools\selenium-server-standalone-2.15.0.jar

Now let's break this down. The first part is of course the cmd application that I want to run followed by /k an argument for cmd that tells it to keep the console window open after launching. This is important as our application may give important information to the console or cease to continue running altogether once closed.

Next, I call Java, in my case I have java in my Windows Classpath so that the term java is actually a shortcut to the Java application on my machine. You can read more about setting up java in your system classpath here.

The Java application accepts an argument of -jar which indicates that we are running a compiled jar application. Followed by the application location.

Apply and close any windows remaining, now double click the shortcut icon and hopefully you see something like the following.

Good luck.

No comments: