Sigh. Java. Why doesn't something like Perl, or Python, or Ruby take over? Oh, well. In the meantime...
Run Your JDK in Headless Mode
...because java is so stupid, it can't do many graphics operations without assuming you must have a display available, implying an X server or other set of windowing libraries. This is only available from a certain JDK version an onward. Definitely 1.4 and up.
java -Djava.awt.headless=true
Importing a Server Certificate into Your JDK
default keystore is kept in $JAVA_HOME/jsr/lib/security/cacerts
default password to that keystor is "changeit"
certs created using openssl work fine, hence, it is easy to import the cert you made for your apache server.
[root@localhost ~]# keytool -import -file /home/mwood/server.crt \
-alias employer -keystore /usr/local/jdk1.5.0_04/jre/lib/security/cacerts
Enter keystore password: changeit
Owner: CN=www.employer.com, OU=Development, O=Employer, L=Boston, ST=Massachusetts, C=US
Issuer: CN=www.employer.com, OU=Development, O=Employer, L=Boston, ST=Massachusetts, C=US
Serial number: 0
Valid from: Wed Feb 15 11:09:06 EST 2006 until: Sat Feb 13 11:09:06 EST 2016
Certificate fingerprints:
MD5: 52:A9:14:8D:6F:80:9C:20:27:A2:92:D6:0B:AD:AF:1E
SHA1: 31:56:AE:5A:5A:65:95:05:00:70:2D:07:32:B1:0A:6B:B4:9E:B0:F1
Trust this certificate? [no]: yes
Certificate was added to keystore
[root@localhost ~]#
Tell Java not to compile code, so that you get line numbers, not "(Compiled Code)", in stack traces:
java -Djava.compiler=none
Get a thread dump from a JVM:
kill -s SIGQUIT <pid of JVM>
or
kill -3 <pid of JVM>
Or, for a JVM on a console, Ctrl-\. The thread dump will go
to whereever STDOUT is going; if you started your JVM with nohup, check
nohup.out.
grep the contents of a jar file:
jar -tvf my.jar 2>&1 | grep string
Java commands are excruciatingly stupid about writing what should be stdout stuff to stderr.
Find a class in any jar file in a directory tree:
First of all, unlike the above tip, it seems that newer versions of jar finally understand the difference between standard out and standard error. Yay! The following shell script takes one argument: a string (usually a class name) that you are looking for in the table of contents of every jar file in your current directory tree. The script is:
#!/bin/sh
for f in `find . -name '*jar'`
do
jar -tvf $f | grep $1 && echo "was found in $f"
done
So just name this shell script find_in_jars.sh and run it like so:
./find_in_jars.sh SomeJavaClassName
Find all TODOs in a codebase (*.java files in this example):
find . -name '*.java' -exec grep -i -H -n "todo" {} \;