run java program with libs from cmd line in bash

#resolve directory absolute path
scriptname=$(echo $0 | sed s/.*\\///g)

if [ “$0” = “./$scriptname” ];then
abspath=$(echo `pwd`/$0 | sed “s/\/$scriptname//g” | sed ‘s/\/\.//g’)
else
abspath=$(echo $0 | sed “s/\/$scriptname//g”)
fi

#find java libraries and separate them with colon
jars=$(find $abspath/lib/ -name \*.jar | xargs echo | sed s/\ /:/g)

#run the main class in JavaClas in xxx.yyy.zzz package
java -classpath $jars xxx.yyy.zzz.JavaClass

Advertisements

One thought on “run java program with libs from cmd line in bash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s