Mega524
Posts: 9
Joined: Tue May 29, 2018 2:26 pm

Create executable of java program

Fri Jun 01, 2018 4:59 pm

I have a java program on my Raspberry Pi that I am currently running using the BlueJ IDE. I would like to make the program executable by clicking on a file or icon on the Raspberry Pi desktop, and I am unsure how to do so. It looks like I can make a JAR file of the .class file, but would I be able to just click on it and have the program run?

User avatar
DougieLawson
Posts: 33791
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Create executable of java program

Sat Jun 02, 2018 8:00 am

Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Mega524
Posts: 9
Joined: Tue May 29, 2018 2:26 pm

Re: Create executable of java program

Mon Jun 04, 2018 12:27 pm

I can create the JAR file, but I cannot seem to figure out how to make it executable just by clicking on it. When I created the JAR file it was zipped, and when I extract it it makes a new file called META-INF, which is very similar to the myManifest file I made when trying to make the JAR file. So how do I make the zipped JAR file into a shortcut that I can run just by clicking on it?

Heater
Posts: 9832
Joined: Tue Jul 17, 2012 3:02 pm

Re: Create executable of java program

Tue Jun 05, 2018 3:43 am

What you can do is create a little shell script that in turn uses the usual "java" command to run your jar file.

This blog post describes this nicely: https://coderwall.com/p/ssuaxa/how-to-m ... executable

The next problem is to create an icon for the Raspi's Window manager that runs that little script when you click it.

I don't use the Raspi desktop so I'm afraid I cannot help there. A search of this forum should find you something.

PiBurner
Posts: 14
Joined: Wed Mar 23, 2016 2:34 pm

Re: Create executable of java program

Wed Jul 11, 2018 5:08 pm

Right click on the .jar file and select 'Open With'. In the command line box enter 'java -jar /[full path to the jar file]' (without the single quote) and check 'Set selected application as default action for this file type'.
I usually add the complete jar file name in the 'Application name' text box, also.

frbsechat
Posts: 2
Joined: Tue Sep 11, 2018 11:21 am

Re: Create executable of java program

Wed Sep 12, 2018 12:43 pm

Easiest way (for me) to get an "runable Jar File" is with Eclipse (using Ant), under some more powerful machine (I tried running Eclipse over a RPI, much too slow). Under Eclipse, Right click over your package/class containing your "main" method, then choose "export" within the popup, then choose "runnable jarfile", then don't forget to tag "save as ant script" if you want to export it again after modification of your java project by double-clicking over the Ant script file (you'll have of course to specify a file name and a path to have it available and visible within your project (type F5 to refresh the Eclipse view if it doesn't appears). I normally get this way jarfiles that run just through double clicking on their file icon.

blackie
Posts: 1
Joined: Fri Sep 14, 2018 2:26 am

Re: Create executable of java program

Fri Sep 14, 2018 2:39 am

I've been using eclipse juno for this. Made an app just like Showbox for android , I used only java for this.
Now, I'm thinking of changing my main coding software for .java files. Any ideas where I would go?
Busy watching movies

Balin
Posts: 9
Joined: Mon Sep 17, 2018 7:43 am

Re: Create executable of java program

Thu Oct 04, 2018 8:07 am

I found the Apache Maven Assembly Plugin, which packs everything, the executable jar needs, into it, very handy. You just have to add the plugin in your pom.xml, and call maven with the goal "package". You can do this with an Eclipse runtime configuration, but of course as a separate process on a build server as well.

Homepage is here: http://maven.apache.org/plugins/maven-a ... index.html
Nice short description is here: https://www.baeldung.com/executable-jar-with-maven (Chapter 2.2)
Regards, Balin.

Return to “Java”

Who is online

Users browsing this forum: No registered users and 3 guests