Running Java program from file manager

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
peter_62au
Level 1
Level 1
Posts: 17
Joined: Wed Apr 29, 2015 4:43 am

Running Java program from file manager

Post by peter_62au »

I'm trying to run a Java program I wrote in netbeans for windows. After a week of searching and trial and error I discovered how to run it from the command line. I feel like an idiot as the command was written at the bottom of the output screen in netbeans. I did learn how to change the java path though so not a total waste. For anyone who might be interested the command I used is java -jar <program name>.
I would however prefer not to have to open terminal everytime to run this. How can I run it either from the file manager or preferibly from a link on the desktop. it will run by double clicking but crashes because it needs the -jar parameter.
altair4
Level 20
Level 20
Posts: 10327
Joined: Tue Feb 03, 2009 10:27 am

Re: Running Java program from file manager

Post by altair4 »

Create your own file association:

Right click any jar file.
Select "Open With" > Other Application
At the bottom where it says "Enter a custom command" enter:

Code: Select all

java -jar
Now when you double click a *jar file it will run "java -jar" automatically.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
peter_62au
Level 1
Level 1
Posts: 17
Joined: Wed Apr 29, 2015 4:43 am

Re: Running Java program from file manager

Post by peter_62au »

Tried that. Doesn't work. Accepts java as the default but not the -jar parameter.
altair4
Level 20
Level 20
Posts: 10327
Joined: Tue Feb 03, 2009 10:27 am

Re: Running Java program from file manager

Post by altair4 »

Then there is something wrong with that particular jar file, you didn't make the association the default for a jar file, or something is wrong with your install of java itself.

EDIT: If you are using Unity, Gnome, Cinnamon, MATE, or XFCE ( and probably LXDE ) you should have a file at /home/your-user-name/.local/share/applications that's named something like this: userapp-java-5QU7WX.desktop

And the contents of that file should look a lot like this:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
NoDisplay=true
Exec=java -jar %f
Name=java
Comment=Custom definition for java
If you don't have such a file then you didn't make the association.
If you have such a file with that content and you can't double click a random jar file to run it then I can't reproduce your symptom. Sorry.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
peter_62au
Level 1
Level 1
Posts: 17
Joined: Wed Apr 29, 2015 4:43 am

Re: Running Java program from file manager

Post by peter_62au »

Did a full search of the file system and couldn't find anything resembling that file. The java path is set correctly and works. I've decided to get around the issue by just using a shell script, not exactly what I wanted or explain the issue but it does allow me to automatically back up the data after the program has run.
altair4
Level 20
Level 20
Posts: 10327
Joined: Tue Feb 03, 2009 10:27 am

Re: Running Java program from file manager

Post by altair4 »

peter_62au wrote:Did a full search of the file system and couldn't find anything resembling that file.
At least now we know the cause of the problem.

Maybe some screenshots would be in order:

This is how you make a file association in Cinnamon: Right click a jar > Open With > Other Application:
Cinn-Association.png
And despite the risk to my emotional well-being I logged into a box running KDE and this is how it looks there: Right Click a jar > Open With > Other
KDE-Association.png
Now KDE being KDE they don't follow the standards for this type of thing so the file is named different: /home/your-user-name/.local/share/applications/java.desktop

And the content of the file is different:
[Desktop Entry]
Exec=java -jar
MimeType=application/x-java-archive;
Name=java
NoDisplay=true
Type=Application
But it appears to work the same.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
peter_62au
Level 1
Level 1
Posts: 17
Joined: Wed Apr 29, 2015 4:43 am

Re: Running Java program from file manager

Post by peter_62au »

That's exactly how I did it using Cinnamon, even before I put up my original post. It does then show java as the default. It even begins to run but crashes as soon as it needs to access a data file. The only way I can make it run properly is entering java -jar <program name> at the command line or using a shell script. Thanks for your help but it appears my computer has Gremlins in it.
Post Reply

Return to “Software & Applications”