Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bash Script

Posted on 2013-02-04
8
Medium Priority
?
530 Views
Last Modified: 2013-02-04
Can someone help me understanding  what the this script is doing?
I found this script on the internet. I would like to create my own script to run my own java programs automatically. I'm new to the linux environment. I appreciate your help.

#!/bin/bash
JAVA_HOME=/usr/lib/jvm/jdk1.6.0_02
CLASSPATH=/home/freddy/myapp/lib/whatever.jar: .
$JAVA_HOME/bin/java -cp $CLASSPATH MyJavaClass
exit 0

Things I do know. I know how to open the terminal and start the vi editor. I have a cheat sheet to help with this. I have added my script directory to the PATH, so my scripts run by using the relative path.

Things I don't know: How to create a jar in eclipse?(Looking it up now.) Where is JAVA_HOME and CLASSPATH.

I'm a newbie and appreciate your help.
0
Comment
Question by:DOCDGA
  • 3
  • 3
  • 2
8 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 38852533
to know the locations you can run below commands from command prompt

echo $JAVA_HOME

echo $CLASSPATH.
0
 

Author Comment

by:DOCDGA
ID: 38852604
I tried running the commands : echo $JAVA_HOME echo $CLASSPATH and the results came back blank
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 1000 total points
ID: 38852611
Ok, they are not set before and are set in the script
:

JAVA_HOME is /usr/lib/jvm/jdk1.6.0_02

and

CLASSPATH is /home/freddy/myapp/lib/whatever.jar: .
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:tel2
ID: 38852707
Hi DOCDGA,

> Can someone help me understanding  what the this script is doing?
I'll give a brief explanation of each line, below.

#!/bin/bash
Run this script as a bash script (i.e. in the borne again shell, which I think is the most common one these days).

JAVA_HOME=/usr/lib/jvm/jdk1.6.0_02
Assign a single path to an environment variable

CLASSPATH=/home/freddy/myapp/lib/whatever.jar: .
Assign 2 paths to an environment variable, the 2nd being "." which means "the current working directory".  The ":" separates the paths, but I doubt the space before the last "." needs to be there.

$JAVA_HOME/bin/java -cp $CLASSPATH MyJavaClass
Run java from /usr/lib/jvm/jdk1.6.0_02/bin/java with switch(es) "-cp" (whatever that means), and arguments "/home/freddy/myapp/lib/whatever.jar: ." and "MyJavaClass".

exit 0
Exit the script, forcing a zero return code, which usually means "success".  Usually having an exit at the end of a script is unnecessary, except if you want to force a particular return code, as in this case.  This means that even if the previous line fails with a non-zero return code, the script will still return a zero return code.
0
 

Author Comment

by:DOCDGA
ID: 38852717
Okay, I'm a little lost. Please forgive me for not understanding but I am new to  programming. I did manage to navigate to through the directories and
locate/usr/lib/jvm
I don't see any jdk file but I see a bunch of directories with names like java-1.5.0-gcj-1.5.0., jre,jre-1.5.0,java-17.0-openjdk-1.7.0.9, jre-1.7.0-openjdk,jre-gcj, and jre-openjdk

Don't know if this makes much since but I'm just trying to learn.
0
 
LVL 12

Expert Comment

by:tel2
ID: 38852723
What output do you get when you issue this command, DOCDGA?
    ls -l /usr/lib/jvm/jdk1.6.0_02/bin/java
Please copy and paste the above command, to avoid typos.
0
 

Author Comment

by:DOCDGA
ID: 38852801
ls: cannot access /usr/lib/jvm/jdk1.6.0_02/bin/java: No such file or directory
0
 
LVL 12

Assisted Solution

by:tel2
tel2 earned 1000 total points
ID: 38852825
Which confirms that that path doesn't exist on your machine.  I don't know the java environment, so someone else will have to help with that issue, sorry.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question