?
Solved

Executing a Jar File through Unix script

Posted on 2009-02-13
6
Medium Priority
?
823 Views
Last Modified: 2012-06-22
It is calling Main-Class in jar file but the classpath is not set weirdly. It is giving me some class not found from the libraries.
#!/bin/ksh
 
DIR=`dirname  $0`
 
# Set new class path
echo "Setting classpath"
 
CLASSPATH=${DIR}/config
 
for i in `ls -1 lib/*.jar`; do
   CLASSPATH=${CLASSPATH}:${DIR}/${i}
done
 
`java -jar -cp $CLASSPATH -Ddir=${DIR} zones.jar`
 
exit 0

Open in new window

0
Comment
Question by:srikanthradix
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 23637995
Just make sure the classpath and DIR is what you want by echoing them before you execute java (for which you don't need backticks)
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 200 total points
ID: 23638043
set necessary env variables within the script itself
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 900 total points
ID: 23638181
Sorry - just noticed. CLASSPATH is completely ignored when you execute Java with -jar. The only classpath that's recognised is Class-Path in the jar's manifest
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Assisted Solution

by:objects
objects earned 900 total points
ID: 23638223
you need to add the (relative) location of the required jars in you manifest using the Class-Path: attribute.
Easiest is to put all the jars in the same dir as your application jar, then it would be like

Main-Class: au.com.objects.MyApp
Clas-Path: a.jar b.jar c.jar

Make sure you leave a couple of blank lines at the end of your manifest

Or alternatively don't use the -jar and include the main class name in your existing script

0
 

Author Closing Comment

by:srikanthradix
ID: 31546766
Manifest thing did the trick. Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23639799
:-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

840 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