Thursday, July 30, 2009

Run .jar file on Linux




Hi everyone,

Today, I am bringing to you a very nice thing, if you have written java code on windows, exported it as a .jar file and used it on Windows but was unable to do this on linux though you have JDK installed on linux, then this is the right place for you !!

To do this surely you must have a correct and runnable java code with a main class.

Steps:
======

If you are using netbeans right click on the project and then click clean and build, on eclipse right click on the project and then choose export and choose as runnnable jar file.

This will create a .jar file in your project folder (for netbeans inside the dist folder).

You will open your nice terminal and start by creating a "launcher" which is a shell script that you create so that it can run your .jar file.

In this example I made a simple watch and the jar file is named SimpleWatch.jar, ok?


you will type:


cd /usr/local/bin


then


gksudo gedit SimpleWatchLauncher.sh


the last command will open the Text editor you copy and paste this

#! /bin/bash
cd /home/khaled/NetBeansProjects/SimpleWatch/dist
java -jar /home/khaled/NetBeansProjects/SimpleWatch/dist/SimpleWatch.jar


Of course you will replace "/home/khaled/NetBeansProjects/SimpleWatch/dist" with the path of the directory that contains your .jar file

Save and exit the Text editor






Type this in the terminal (Make sure you are in /usr/local/bin)

sudo chmod +x /usr/local/bin/SimpleWatchLauncher.sh



That's it you are done !!!


now open your terminal and type:

cd /usr/local/bin/


Click enter
then type


SimpleWatchLauncher.sh



Your application will Run isA and you will now that Java is really platform independent :D

No comments:

Post a Comment