LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-07-2007, 12:51 PM   #1
netjack
Member
 
Registered: Sep 2003
Location: Italy
Distribution: ubuntu 12.04 64 bit
Posts: 90

Rep: Reputation: 15
How to add Java applications to panel


Hi,

I have some Java applications written by myself and would like to place executable buttons in the graphical Desktop panel. For instance, I have my jar file, then I have another file "MyExecutable" that has the command java -jar myfile.jar, which I have made "executable", i.e. if I double click on it, ubuntu asks me if I want to run the program or show its contents.

I'd like to have a button in the gnome panel I could start the program with; when I configure the custom launcher dialog, I do not know what to insert in the "command" field (/home/Desktop//.MyExectuable does not work).

Thanks for your help.
 
Old 11-07-2007, 12:52 PM   #2
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Code:
/home/Desktop/MyExecutable
should work, if there's nothing curious about it.

EDIT: you launch it like "./MyExecutable" from the terminal if your working directory is the directory where the executable is, because the dot file "." means the current directory. Therefore "./" means "inside the current directory", and "./MyExecutable" means "run MyExecutable from within this current directory". You can also run it with full path, like "/home/username/Desktop/MyExecutable", which is what you use with the launcher, because the launcher's "current working directory" isn't necessarily what you want, if it even is aware about such a thing.

Last edited by b0uncer; 11-07-2007 at 12:54 PM.
 
Old 11-07-2007, 01:30 PM   #3
netjack
Member
 
Registered: Sep 2003
Location: Italy
Distribution: ubuntu 12.04 64 bit
Posts: 90

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by b0uncer View Post
Code:
/home/Desktop/MyExecutable
should work, if there's nothing curious about it.
Code:
/home/myname/Desktop/MyExecutable
does not work. Thanks for the explanations about the ./ !

This is how I created the "MyExecutable": with gedit in a new file, added "java -jar MyJavaApp.jar". Wrote to disk with no extension. With gnome, under "permissions", I changed it to executable. Gnome however still recognizes this of type "plain text document".
 
Old 11-07-2007, 04:28 PM   #4
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 73
Try entering the commands as
Code:
java -jar /path/to/myfile.jar
 
Old 11-07-2007, 04:31 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by netjack View Post
Gnome however still recognizes this of type "plain text document".
Two things:
  1. Try making your file a valid shell script (i.e., complete with she-bang followed by interpreter). This doesn’t require too much work:
    Code:
    #!/bin/sh
    
    java -jar /home/myname/Desktop/MyJavaApp.jar
  2. If you want to be cool, you can register a jar-file loader with the kernel (using binfmt_misc). That is, you can teach the kernel to recognize the extension “.jar” (or, in the class of naked .class files, the magic number 0xCAFEBABE), and associate it with a loader (which is probably a shell script you write). Then, all that’s required to execute a java program is:
    Code:
    chmod +x MyJavaApp.jar
    ./MyJavaApp.jar
    Or
    Code:
    chmod +x MySmallJavaApp.class
    ./MySmallJavaApp.class
If you need help with the second method, just post.
 
Old 11-08-2007, 12:47 PM   #6
netjack
Member
 
Registered: Sep 2003
Location: Italy
Distribution: ubuntu 12.04 64 bit
Posts: 90

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by reddazz View Post
Try entering the commands as
Code:
java -jar /path/to/myfile.jar
Thanks, this worked !
 
Old 11-08-2007, 12:49 PM   #7
netjack
Member
 
Registered: Sep 2003
Location: Italy
Distribution: ubuntu 12.04 64 bit
Posts: 90

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by osor View Post
Two things:
[*]If you want to be cool, you can register a jar-file loader with the kernel (using binfmt_misc).
That would be nice indeed. How do I activate (and, possibly) deactivate that in the kernel?

Thx!
 
Old 11-08-2007, 03:57 PM   #8
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by netjack View Post
How do I activate (and, possibly) deactivate that in the kernel?
Before we do this, let’s create a jar-file loader (which we will later use). The prospect of this loader is that you execute your program:
Code:
jarloader /path/to/program.jar
We will place it in /usr/local/bin so it doesn’t interfere with system files (all further excerpts assume you have root access):
Code:
cat > /usr/local/bin/jarloader << EOF
#!/bin/sh

/usr/bin/java -jar $@
EOF
(you might change the /usr/bin/java so it matches your actual java interpreter)

Let’s make it executable:
Code:
chmod +x /usr/local/bin/jarloader
Now let’s get on with using binfmt_misc.The concept is pretty simple (a more detailed explanation may be found here). First, you load the binfmt_misc module:
Code:
modprobe binfmt_misc
Then, you mount the virtual binfmt_misc filesystem. This will allow you to see and register miscellaneous “binary formats” with the kernel. The canonical place to mount it is within the /proc directory itself:
Code:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
Now, we register our file by writing a string containing a sequence of colon-delimited fields (which are explained in detail in the documentation) to the file register:
Code:
echo ":JAR:E::jar::/usr/local/bin/jarloader:" > /proc/sys/fs/binfmt_misc/register
You now see new file in the virtual filesystem. Its contents may be viewed by simply reading them:
Code:
cat /proc/sys/fs/binfmt_misc/JAR
You may temporarily disable this format by writing a 0 to it:
Code:
echo "0" > /proc/sys/fs/binfmt_misc/JAR
It may be re-enabled by writing a 1 to it:
Code:
echo "1" > /proc/sys/fs/binfmt_misc/JAR
It may be removed completely by writing -1 to it:
Code:
echo "-1" > /proc/sys/fs/binfmt_misc/JAR
A different solution may be found for naked class files (usually shorter programs). It is different for two reasons:
  1. The java interpreter does not expect the full path to the class file as an argument. Instead, it assumes you have a suitable definition of CLASSPATH and that you specify the name of the class itself (without the extension). So your wrapper program may look more like this (which is a tad more complicated).
  2. Instead of matching the extension (which is somewhat crude), we can use the fact that all java classes begin with the first four bytes 0xCAFEBABE. So instead of matching an extension, we match a magic number. So your registration might end up looking like:
    Code:
    echo ':Class:M::\xca\xfe\xba\xbe::/usr/local/bin/javawrapper:' > register
    instead.
You can also add the relevant commands to your startup scripts to get automatic registering of formats.
 
  


Reply

Tags
application, executable, gnome, java, panel


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't to do two things at once nor add to the panel {e} Mandriva 2 08-04-2007 12:27 AM
Gnome 'Applications' 'Places' and 'Desktop' disappeared from top panel sixerjman Linux - Software 4 06-19-2007 10:18 AM
can't customize gnome panel applications menu - fc3 steve_mckay Fedora 1 12-23-2004 09:47 PM
Changing icons for shortcuts and adding applications to KDE panel linuxRunner Linux - Newbie 5 07-31-2004 12:36 PM
How to add the shotcut to the panel? ICO Slackware 5 02-06-2004 01:33 AM


All times are GMT -5. The time now is 05:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration