LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2006, 04:37 PM   #1
xlinuks
Member
 
Registered: Jan 2006
Location: White House
Distribution: Ubuntu 8.10
Posts: 39

Rep: Reputation: 15
Run java from shellscript


Hello,
I have a little Java program that is supposed to be run with a custom amount of memory, to do this I need to create a shell script (I've created a .bat script for windows with no problem). BUT, under Linux my script runs correctly only from the command line - I need to run it at double click as well. The script is supposed to launch a .jar (Java executable) file that's in the same directory. Here's my script (called "start_java"):
Code:
#! /bin/sh
#cd $PWD
java -Xms64m -Xmx256m -jar ./MyApplication.jar
It runs successfully from the command line like "./start_java" & Enter.
At double click it wont launch - I think it's about specifying the directory where Java should find the "MyApplication.jar" - here is my problem since I don't know how to do it. From the command line we say "./" to specify the current dir, but using the double click method - the application (java) thinks probably that the current folder is the directory where it is installed.
Hope you got me correctly (the CD $PWD didn't work either).
Please help!
 
Old 12-10-2006, 05:35 PM   #2
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 62
First there is no space in the first line. It is one single word as one might say.
#!/bin/bash

The cd $PWD is actually what? You need to define the string variable $PWD

Brian
 
Old 12-10-2006, 05:59 PM   #3
xlinuks
Member
 
Registered: Jan 2006
Location: White House
Distribution: Ubuntu 8.10
Posts: 39

Original Poster
Rep: Reputation: 15
Thanks for the hint. I realized whats the matter: when using double click the "PWD" variable points to my home dir, instead of the directory from where the shell script has been launched - and I have no clue how to fix this.
Code:
#!/bin/bash
nowdir=$PWD
echo $nowdir >> /home/brian/Desktop/thefile.txt
java -Xms64m -Xmx256m -jar $nowdir/MyApplication.jar
-from the command line I get a file (thefile.txt) on the desktop containing "/home/brian/Desktop"
-by double clicking the shellscript (from the Desktop as well) I get same file with only "/home/brian"
So, my problem is: How to let the shellscript correctly identify the folder it has been launched from?

Last edited by xlinuks; 12-10-2006 at 06:00 PM.
 
Old 12-10-2006, 06:07 PM   #4
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 62
Is the same file being overwritten?
First run it like you say, then delete the thefile.txt and run it again where you want the second time. If it is correct then the second attempt is not forcing and overwrite.

Brian
 
Old 12-10-2006, 07:38 PM   #5
xlinuks
Member
 
Registered: Jan 2006
Location: White House
Distribution: Ubuntu 8.10
Posts: 39

Original Poster
Rep: Reputation: 15
I create the "thefile.txt" from the shell script just to prove that the shellscript behaves differently when it is being launched by double-click or from the command line - both cases have different understanding about the 'current directory' - which is why I can't run the "MyApplication.jar" file double-clicking the launcher ( the "start_java" file ).
Thanks for your time.

Last edited by xlinuks; 12-10-2006 at 07:39 PM.
 
Old 12-10-2006, 08:46 PM   #6
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
I have the same problem, but I do not rely on desktop icons. State the the PATH environment variable or use the full path to the program.

The reason why the script is behaving strangly. All programs that are loaded gets their own seperate environment because Linux is a multi-tasking and a virtual memory OS. To get the script run in the same environment, you type ". [script name]". The dot says in this environment, run this script.

In your script, I suggest adding . on the same line that reads java before java. This will make it easier for Linux to run the program in the same environment as the script is run.
 
Old 12-11-2006, 03:53 PM   #7
xlinuks
Member
 
Registered: Jan 2006
Location: White House
Distribution: Ubuntu 8.10
Posts: 39

Original Poster
Rep: Reputation: 15
Putting the point before 'java' didn't help either
 
Old 12-11-2006, 04:06 PM   #8
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 62
Not a very good script writer so out of ideas.

Brian
 
Old 12-11-2006, 04:50 PM   #9
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Assuming MyApplication.jar is in $HOME/bin/javaprog
Code:
#!/bin/sh
#PATH="/bin:/sbin:/usr/bin:/usr/sbin"
PROGRAM_PATH="$HOME/bin/javaprog"
cd "$PROGRAM_PATH"
java -Xms64m -Xmx256m -jar MyApplication.jar
unset PROGRAM_PATH
Please read my previous post thoroughly.
 
Old 12-12-2006, 03:36 AM   #10
xlinuks
Member
 
Registered: Jan 2006
Location: White House
Distribution: Ubuntu 8.10
Posts: 39

Original Poster
Rep: Reputation: 15
That's the problem,that there's no way to know where the end user might unzip the application.
 
  


Reply


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
Help Shellscript paraiso Linux - Newbie 7 05-12-2005 08:25 AM
Lockscreen Shellscript 2 paraiso Linux - General 1 05-11-2005 06:30 PM
shellScript help paraiso Linux - Newbie 2 05-10-2005 08:09 PM
ShellScript sharadgana Programming 1 12-16-2004 02:16 PM
Java applets run fine in Konqueror, but won't run in MS IE. OAnimal Linux - Software 7 12-04-2002 07:32 AM


All times are GMT -5. The time now is 04:07 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration