Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Creating an executable icon(Doable in Eclipse?)
Creating an executable icon [message #671985] Thu, 19 May 2011 14:08 Go to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
I'm currently part of a team designing a certain Java application; my part was coding a file called GUI.java, with which the entire program is launched. Now, it works fine when I launch it through Eclipse, but I would like to change it so that it can launched simply by clicking a desktop icon.

Can this be done with Eclipse? I've tried to use its "export" functionality to create a .jar, but I can only execute that by opening a command prompt and typing java -jar GUI.jar...
Re: Creating an executable icon [message #672005 is a reply to message #671985] Thu, 19 May 2011 14:44 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Do you mean from your OS? Which one?

If java is set up correctly on windows, for example, double-clicking on any .jar in windows explorer will try and launch it using java -jar whatever.jar.

Or do you mean something else?

PW


Re: Creating an executable icon [message #672219 is a reply to message #672005] Fri, 20 May 2011 11:17 Go to previous messageGo to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
Paul Webster wrote on Thu, 19 May 2011 10:44
Do you mean from your OS? Which one?

If java is set up correctly on windows, for example, double-clicking on any .jar in windows explorer will try and launch it using java -jar whatever.jar.

Or do you mean something else?

PW


Well, I'm working on Linux, and odds are most of the people who will use this program will be too...
Re: Creating an executable icon [message #672241 is a reply to message #672219] Fri, 20 May 2011 12:43 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It works the same way on linux. Associating "java -jar" with .jar files will launch the jar with java on any double-click (desktop or system file browser)

PW


Re: Creating an executable icon [message #675405 is a reply to message #672241] Tue, 31 May 2011 12:33 Go to previous messageGo to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
Paul Webster wrote on Fri, 20 May 2011 08:43
It works the same way on linux. Associating "java -jar" with .jar files will launch the jar with java on any double-click (desktop or system file browser)

PW


Wouldn't that work only on my machine, though? I need it to also work for clients who download the thing...

Anyway, tried a different approach: Created a shell script "script.sh" that executed the .jar, then created a desktop launcher designed to execute script.sh; this worked fine, except for one problem: its command was "/home/omaler/[...]/script.sh"; in other words, it was designed to work with the folder hierarchy specific to my machine. So I tried instead to make it more universal, by making it execute the script found in the same folder (rather than giving it an absolute path):
command: $(dirname %k)/script.sh
work path: ./

While it did launch the program...It encountered execution errors I never had while launching it with Eclipse or with the previous launcher. No idea how that's even possible.
So, I tried to obtain more data on the error by going into the launcher's advanced options, and checking the "run in terminal" option. But then, when I tried to run it and it opened a terminal...the only message it printed was that it couldn't find the .jar file. I tried checking the "run in terminal" option with the other launcher (the one using an absolute path, which worked just fine), and got the same error.

I'm...stumped. Maybe it's my ignorance of Linux launchers, but I don't understand where these errors could come from.
Re: Creating an executable icon [message #675415 is a reply to message #675405] Tue, 31 May 2011 13:10 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Ouri.maler.gmail.com wrote on Tue, 31 May 2011 08:33


Wouldn't that work only on my machine, though? I need it to also work for clients who download the thing...



For executable jars to work, every client must make sure "java -jar" is used to execute jars.

Quote:


Anyway, tried a different approach: Created a shell script "script.sh" that executed the .jar ...


To create that kind of script reliably, you need something like:

#!/bin/bash
PROG=$0
PROG_DIR=$( dirname $( readlink -f "$PROJ" ) )

java -classpath "$PROG_DIR/lib1.jar:$PROJ_DIR/lib2.jar" com.example.MyMain


the first 2 lines make sure you have the path to your script directory, regardless of how the script is executed.

As for your foray into linux launchers, if the trick of getting your script dir doesn't fix it you'll need to follow up with the linux launcher app guys.

PW


Re: Creating an executable icon [message #676795 is a reply to message #675415] Mon, 06 June 2011 14:46 Go to previous message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
Ended up with the following script:

#!/bin/bash
PROG=$0
PROG_DIR=$( dirname $( readlink -f "$PROG" ) )

java -jar "$PROG_DIR/GUI.jar"


An office colleague helped me run it in a terminal. Apparently, the exception occurs when it can't find "bin/oc_linux"; he says this is due to problems with selecting the right working directory.
Previous Topic:Help w/ Accessing Java Browsing Elements
Next Topic:ProjectExplorer and Navigator disappeared
Goto Forum:
  


Current Time: Tue Apr 23 08:20:53 GMT 2024

Powered by FUDForum. Page generated in 0.03898 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top