Tuesday, November 15, 2016

Running java class from CLI in Debian

Prerequisite:
To set Java Environment for all users, add/edit /etc/environment:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
CLASSPATH=".:/usr/share/java/mysql.jar:/usr/share/java/postgresql-jdbc4.jar"
I have a java class BlockedSSH.class. It required mysql.jar library. To run BlockedSSH.class from CLI and including all java library on runtime environment, use option -classpath:
$ /usr/bin/java -classpath $CLASSPATH:/root/java/ BlockedSSH
Java will find any java library that already added in /etc/environment. To check classpath
$ set | grep CLASSPATH
CLASSPATH=.:/usr/share/java/mysql.jar:/usr/share/java/postgresql-jdbc4.jar

No comments:

Post a Comment