set JAVA_HOME environment variable

set JAVA_HOME as environment variable in linux

export JAVA_HOME=$(readlink -f /usr/bin/javac) | tr -d '/javac'

to see value of the variable in linux

echo $JAVA_HOME

set JAVA_HOME as environment variable in windows

setx -m JAVA_HOME "C:\Program Files\Java\jdk1.6.0_27\bin"

to see value of the variable in windows

echo %JAVA_HOME%"
Advertisements

search for string in big source code linux

search for tty string in all .sh files in /etc dir

for i in $( find /etc -name *.sh );do OUT=$( grep -i 'tty' $i ); test "$OUT" && echo -e "\n$i\n$OUT"; done

search for database string in all .php files in local dir

for i in $( find . -name *.php );do OUT=$( grep -i 'database' $i ); test "$OUT" && echo -e "\n$i\n$OUT"; done

search for log4j string in all .java files in local dir

for i in $( find . -name *.java );do OUT=$( grep -i 'log4j' $i ); test "$OUT" && echo -e "\n$i\n$OUT"; done

how to configure log4j.properties

vi /path/to/log4j.properties

Output Java Log to Console

# Root logger level option
log4j.rootLogger=ALL, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Output Java Log to File

# Root logger level option
log4j.rootLogger=ALL, file

# Direct log messages to a log file in /tmp
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/tmp/allLogsJava.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Output Java Log to Console and File

# Root logger level option
log4j.rootLogger=ALL, file, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Direct log messages to a log file in /tmp
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/tmp/allLogsJava.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

list content of jar file

list content of only one jar file

jar tf file.jar

list content of all jar files in one dir

for i in $( ls /path/to/jars/*.jar );do jar tf $i; done

list content of all jar files in current dir and sub dirs

for i in $( find . -name *.jar );do jar tf $i; done

which jar contain a specific class file, searching in multiple files

for i in $( find /path/to/jars/here -name *.jar );do OUT=$( jar tf $i | grep insertClassNameHere ); test "$OUT" && echo -e "\n$i\n$OUT"; done

some packages that contain jar binary in debian, install one:

openjdk-7-jdk
openjdk-8-jdk-headless