?
Solved

Bash Script

Posted on 2013-02-04
8
Medium Priority
?
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

718 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