likeGreen
likeGreen

Reputation: 1079

Run a jar using a shell file and specify classpath and properties file path

I've compiled a Spring Maven project JAR. My dependencies are all in a directory labeled lib. How to execute my JAR while specifying it should use the LIB/* as the classpath and also use log4j.xml and a properties file called marker.properties. My marker.sh

LIB=$INSTALL_PATH/lib
echo "$LIB"  # outputs usr/local/app/lib
export CLASSPATH=$(JARS=("$LIB"/*.jar); IFS=:; echo "${JARS[*]}")
PARM="-Dlog4j.configuration=/usr/local/Marker/log4j.xml"
java $PARM -jar /usr/local/Marker/marker-1.0.jar

But on running this I get the following error as it is not able to find the jars in the classpath

Exception in thread "main"java.lang.NoClassDefFoundError: org/springframework/context/ConfigurableApplicationContext                   at java.lang.Class.getDeclaredMethods0(Native method)

However, this command is able to load the jar from classpath, but I am unable to add the properties file

java -cp /usr/local/Marker/marker-1.0.jar:"$LIB"/* com.package.Marker

Upvotes: 0

Views: 3240

Answers (2)

likeGreen
likeGreen

Reputation: 1079

java -cp /usr/local/Marker/marker-1.0.jar:"$LIB"/* com.package.Marker worked perfectly fine. I needed to add .properties file and log4j.xml in folder where jar was placed

Upvotes: 1

jwrh
jwrh

Reputation: 1

You can specify the classpath using the -classpath (or -cp) flag; for example:

~$ java -jar package.jar -classpath /path/to/classpath/*

For more information, see the following documentation.

Upvotes: 0

Related Questions