Solved

Bash Script

Posted on 2013-02-04
8
518 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 64
restrict decimal places for double datatype 10 34
Can't connect to FTP 18 110
SSH in linux 9 71
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

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