How to create windows shortcut using Ant?
Why do you need to create a shortcut using Ant? When do you need to create that ? These might the questions that you will be thinking at this moment when you had a look into this topic. Yep I am here to answer these questions. I just made this topic just to create a buzz thats it but actually you can make Ant to execute any operating system specific commands through your build. It may be shortcut, or if you want to execute any operating system specific command you can make use of this tutorial. Ant currently supports widely used and famous operating systems like Windows, Apple, Linux, Solaris, AIX etc. You can get the list of supporting operating system from sun specification. You can get your current operating system by executing the following line of code in your java program
System.getProperty( "os.name" );
When do you need to use this? This may not be useful for web application developers but they can also use this while building their enterprise or web application to automate few things. But desktop application developers who may use Swing sets etc may find this tip very useful. You can achieve this by using Exec Task in Ant which is the counter part of Runtime.exec in java. Here I am not going to explain you about How to run or create Ant Build. It does not fall under this scope of short tutorial.
Here we go, before getting into the tutorial we will see how to execute a windows command to get the environmental variable path
cmd is the command prompt for windows higher than win 98 and ‘/c’ is mandatory to execute the command in the command shell. To know more about Exec task kindly refer here. Now coming to the point, to create a shortcut unless you don’t have any Windows Resource Kits or read made utilities you have to use VB Script to create shortcuts. The script will be making use of WScript. Shell of windows to do the job. Kindly follow the code snippet given below which creates a shortcut file for a java archive file,
Save the above code as shortcut.vbs. Pls find the corresponding code snippet for part of the ANT Build that uses exec task
Related posts:









“Ant could not find the task or a class this task relies upon.”
I’m running in eclipse
Comment by Paul — July 28, 2008 @ 7:11 pm