Powered By Blogger
Showing posts with label computer. Show all posts
Showing posts with label computer. Show all posts

Tuesday, January 24, 2012

How to Run a Java app in Linux

Greetings everyone! I know it has been awhile since I have written anything and I am sorry for that. The good news is that I am working on two great stories and they are proving to be more difficult than expected. As I finish them, they will surface so rest assured that they are coming!!

Now, onto the main event-Running a java app in Linux!!

There are many great java apps out there and if you are lucky enough, they will run without a hitch. This is usually the case if you download them from the software center or the author of the app includes a well written README that includes installation directions and some trouble shooting for newbies. If this ins't the case, you are left with a .jar file in your downloads folder. Question is, WHAT IS THIS MYSTERIOUS FORMAT AND WHAT DO I DO WITH IT?

To be brief, a .jar, .tar or .tar.gz are package folders that have been compressed. For those fimilar with windows, this is similar to the infamous .zip and or .7zip and other variations. The key is to understanding how to open and compile them in the terminal (very similar to the command line for windows users). The terminal is a scary place for non experienced users because everyone is use to the GUI that the OS presents us with. The GUI refers to "General User Interface" which are the nice things you see on the screen. Now for lack of a better, educated explanation, everything the typical user sees on the screen is a gui and the processes behind them are run in terminal space. It is possible to do all of your computing needs from a terminal and in fact, a select few in the linux community choose to spend the majority of their time in this minimal environment. 

 This is the Desktop GUI
 Package Manager GUI
Software Sources GUI (PPA locations etc)


"So the terminal is the command space is the command center of the computer, fine, but I still don't know how to use it" is what you might be thinking at this point. Luckily, you can get terminal work done easily and quickly using forum posts where others have had similar issues. I was able to find relatively similar posts to my problem and find a solution!

Case and Point

I wanted to find good mind mapping programs similar to inspiration. Inspiration is a great piece of software that is very helpful, but it costs money. I am a poor college student and prospective teacher and lack the funds to be fortunate enough to support the developers so I looked for an alternative. A great website to look for such alternatives is called alternativeto and it pointed me to a program called VUE. This stands for Visual Understanding Environment and can do similar tasks to inspiration and prezi. "Great!", I thought, "Two birds with one stone. A mind mapping application with the ability to be a non linear presenter." I clicked on the download now button and saw that it was available for mac, windows and linux. "Perfect, its cross platform!", was my first thought. I grabbed the linux package and was ready to go until I saw the scary .jar extension.

Now I have been using linux for a number of years but an still in many shapes and forms, a newbie. I have dealt with .jar files in the past, but I am waaaaaaaaaaaaay rusty on the topic. So what do I do? Google searched "how to install a jar file in linux" which brought me to a vast amount of page hits. I found some great sites that explained to me what a jar was, but I needed to install it! I used two main resources to solve my issue. To actually find a command to launch a jar I looked at linuxforums.org which had information I needed. Now I could launch the program, but I didn't want to open up a terminal window every time I wanted to use it. VUE has a support forum and I found an easy way to set it up with a pretty application icon and launcher here.

When someone in a forum posts terminal commands, they are generally in a window that you can copy the text from. For instance, the command that I needed was:

java -jar something.jar


This command let me open the terminal and run the application. I had the jar file on my desktop, so to run it I did this:

cd Desktop

This changed my directory from the home directory to the desktop. Capital letters are important, so when someone posts code, do it correctly!!! Also, take notice of folder names and file extensions. Now I ran the code:

java -jar VUE.jar

Notice that something.jar was replaced by the file extension of the program. Hooray! I was able to run it, but I didn't want to do these steps every time I wanted to use the program. So by going to the VUE forums, I found how to create a .desktop extension. 

Now I won't lie, I don't know anything about this. Don't know what it means but I have an idea of what it does, so I was able to try several times and finally make it work. The key lesson, DO NOT GET FRUSTRATED! Part of using linux is collaboration and effort on the users part. I collaborated to find the code to run what I wanted, now it was up to me to set it up. The poster had the command:

sudo gedit /usr/share/applications/vue.desktop  

so I copied and pasted it into the terminal. (****Note: when pasting into terminal, ctrl+v does not work!! You must use ctrl+shift+v to successfully paste in text)

Upon entering this code, a simple text editor opened up with a lot of mumble jumble that I didn't understand:





  • [Desktop Entry]  
  • Encoding=UTF-8  
  • Name=VUE  
  • Categories=Office  
  • Exec=java -jar /home/rohn/bin/VUE.jar  
  • Icon=/home/rohn/Pictures/Images/Downloaded Icons/vue.gif  
  • StartupNotify=false  
  • Terminal=false  
  • Type=Application  
  • Comment=Visual Understanding Environment Application  
  • StartupWMClass=tufts-vue-VUE  


  • I did however see the familiar command I learned earlier that actually launched the application. So what did I do? I evaluated where the poster had their files located and set mine up in a similar fashion. The execute command was looking at this person's home directory then in the bin folder and then at the jar file. So all I had to do was place the file into a folder and tell the command where to look for it. EASIER SAID THEN DONE! For frustration sake let me tell you how to do it. 

    Open up your file explorer which should look something like this:




    Now you need to navigate backward towards the root directory which looks like this "/" and you do that by clicking the back arrow next to home. The following screen should look like this:


    Now find your way into the "usr" folder. Once in there, RIGHT click on the "bin" folder and choose to open as administrator, depending on your settings you already may be the admin, but if not, then you must do this or else you will not be able to copy anything into it. Once you have the "bin" folder open as the admin, create a new folder called VUE.

    UPDATE : In New Versions of Linux Mint, you need to select run as root





    I have circled the new folder I created in yellow so you can see what it looks like. Now open up the folder and place in the jar file.

    So close to being done!!!! Final steps to make it look pretty.

    You can close all the windows now if you want so that you aren't feeling overwhelmed (don't close my blog though) and open up a terminal. Type in that little code from above to create a .desktop file for VUE.

    sudo gedit /usr/share/applications/vue.desktop  

    You will see the previous user's information, but now it is time to enter your own. Here is what mine looked like:


    [Desktop Entry]
    Encoding=UTF-8
    Name=VUE
    Categories=Office
    Exec=java -jar /usr/lib/VUE/VUE.jar
    Icon=/home/kyle/Pictures/vue.gif
    StartupNotify=false
    Terminal=false
    Type=Application
    Comment=Visual Understanding Environment Application


    Notice that I have it pointing to the usr/lib/VUE/VUE.jar area. This is because of our previous step with creating a folder and placing the jar file in said folder. If you do this successfully (replacing "kyle" with your user name) then you should be able to find VUE in your office applications. Now, there may not be an icon for the application. If this is the case, you can download one and in the "icon" tell it where to look. Notice that mine is in home/kyle/Pictures/vue.gif yours could be set up anyway you want by putting it in a location and telling the computer where to look.


    Well that's it! Now, this was done for the application VUE but in theory it could be applied to any jar file that does not install nicely. Hope you enjoyed this brief tutorial and hopefully it helps you and others in the future!