Solved

Bash Script

Posted on 2013-02-04
8
513 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 250 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
 
LVL 11

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 11

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 11

Assisted Solution

by:tel2
tel2 earned 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now