Solved

Bash Script

Posted on 2013-02-04
8
521 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
The viewer will learn how to implement Singleton Design Pattern in Java.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

726 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