Executing a Jar File through Unix script

Posted on 2009-02-13
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.

DIR=`dirname  $0`

# Set new class path

echo "Setting classpath"


for i in `ls -1 lib/*.jar`; do



`java -jar -cp $CLASSPATH -Ddir=${DIR} zones.jar`

exit 0

Open in new window

Question by:srikanthradix
    LVL 86

    Expert Comment

    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)
    LVL 40

    Assisted Solution

    set necessary env variables within the script itself
    LVL 86

    Accepted Solution

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

    Assisted Solution

    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

    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


    Author Closing Comment

    Manifest thing did the trick. Thanks
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    wordsCount challenge 10 49
    advance java 4 34
    allStar challenge 1 27
    create a gui in perl 3 20
    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    758 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

    14 Experts available now in Live!

    Get 1:1 Help Now