Thursday, November 18, 2010

Set JVM default property with _JAVA_OPTIONS

export _JAVA_OPTIONS=-Djava.awt.headless=true

java |more
Picked up _JAVA_OPTIONS: -Djava.awt.headless=true


Setting JVM -Djava.awt.headless=true is necessary if X server is not available.
Without this property following error is thrown:

Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using '' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:155)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at sun.font.FontManager.initSGEnv(FontManager.java:1307)
at sun.font.FontManager.findFont2D(FontManager.java:1984)
at java.awt.Font.getFont2D(Font.java:455)
at java.awt.Font.canDisplay(Font.java:1904)
at java.awt.Font.canDisplayUpTo(Font.java:1970)
at java.awt.font.TextLayout.singleFont(TextLayout.java:451)
at java.awt.font.TextLayout.<init>(TextLayout.java:509)
at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1675)

Thursday, November 4, 2010

Parse connection string using Java RegEx

http://download.oracle.com/javase/tutorial/essential/regex/index.html

http://download.oracle.com/javase/6/docs/api/java/util/regex/package-summary.html

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestRegEx {

/**
* @param args
*/
public static void main(String[] args) {

String input = "dbuser:passwd@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=dbhost)(PORT=1520)))(CONNECT_DATA=(SID=MY_DB)))";

getParam(input, "Host");
getParam(input, "HOST");
// getParam(input,"xHOST");

Pattern pattern = Pattern.compile("(\\w+)@(\\w+)/(\\S+)");
Matcher matcher = pattern.matcher("username@hostname//dir1/dir2");

if (matcher.matches()) {
System.out.println("User " + matcher.group(1));
System.out.println("Host " + matcher.group(2));
System.out.println("Dir " + matcher.group(3));
}

}

public static String getParam(String input, String paramName) {

Pattern pattern = Pattern.compile(paramName + "=(\\w+)",
Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input);

System.out.println("Matching " + pattern.pattern());

if (matcher.find()) {
System.out.println("Matched " + matcher.group(1) + " in "
+ matcher.group(0));
return matcher.group(1);
} else {
throw new RuntimeException("Cannot find db connection parameter "
+ paramName + " in " + input);
}

}

}

Saturday, October 23, 2010

Configure Java logging file handler

http://download.oracle.com/javase/6/docs/api/java/util/logging/package-summary.html


java.util.logging.config.file defines file used
by LogManager to configure root logger

FileHandler

%g the generation number to distinguish rotated logs

java.util.logging.FileHandler.count specifies how many output files to cycle through (defaults to 1).

http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ317_021.htm

FileHandlers for non-root logger must be specified using Java.

FileHandler fh = null;
try {
fh = new FileHandler("dave." + System.getenv("serverName")+ "%g.log",
500000,
10
);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

lgr2.addHandler(fh);

Wednesday, September 8, 2010

JDK Tools and Utilities

JDK Tools and Utilities

Monitoring and Management

Java Troubleshooting, Profiling, Monitoring and Management Tools

Java VisualVM


jvisualvm

A graphical tool that provides detailed information about the Java technology-based applications (Java applications) while they are running in a Java Virtual Machine. Java VisualVM provides memory and CPU profiling, heap dump analysis, memory leak detection, access to MBeans, and garbage collection.

jconsole A JMX-compliant graphical tool for monitoring a Java virtual machine. It can monitor both local and remote JVMs. It can also monitor and manage an application.

Monitoring Tools

jps JVM Process Status Tool - Lists instrumented HotSpot Java virtual machines on a target system.

jstat JVM Statistics Monitoring Tool - Attaches to an instrumented HotSpot Java virtual machine and collects and logs performance statistics as specified by the command line options.

Troubleshooting Tools

jinfo Configuration Info for Java - Prints configuration information for a given process or core file or a remote debug server.

jhat Heap Dump Browser - Starts a web server on a heap dump file (eg, produced by jmap -dump), allowing the heap to be browsed.

jmap Memory Map for Java - Prints shared object memory maps or heap memory details of a given process or core file or a remote debug server.

jsadebugd Serviceability Agent Debug Daemon for Java - Attaches to a process or core file and acts as a debug server.

jstack Stack Trace for Java - Prints a stack trace of threads for a given process or core file or remote debug server.

Tuesday, June 15, 2010

Override Weblogic config.xml values with weblogic.Server JVM property

Oracle® Fusion Middleware Command Reference for Oracle WebLogic Server
11g Release 1 (10.3.1)
weblogic.Server Command-Line Reference

When you use a startup option to override a configuration value, the server instance uses this value for the duration of its life cycle

http://download.oracle.com/docs/cd/E12839_01/web.1111/e13749/weblogicserver.htm#i1031832

For to override listen address stored in config.xml add in start script
-Dweblogic.ListenAddress=host

This startup option overrides any listen address value specified in the config.xml file. The override applies to the current server instantiation; it does not modify the value in the config.xml file. Use the Administration Console or WLST to modify the config.xml file.

Wednesday, June 9, 2010

Eclipse Weblogic OEPE split and exploded deployment

Oracle Enterprise Pack for Eclipse 11gR1 (11.1.1.5)
http://www.oracle.com/technology/software/products/oepe/oepe_11115.html

allows split and exploded deployment directory structure.

For existing projects use linked files to create projects deployable through OEPE.


Forum: Enterprise Pack for Eclipse

http://forums.oracle.com/forums/forum.jspa?forumID=578&start=0

Thursday, June 3, 2010

Encrypt Weblogic boot.properties using weblogic.security.Encrypt

# directory must be created for managed servers because it does not exist yet
mkdir -p ${DOMAIN_HOME}/servers/${SERVER_NAME}/security

echo "username=${ADMIN_USER}\npassword=\c" > ${DOMAIN_HOME}/servers/${SERVER_NAME}/security/boot.properties

${JAVA_HOME=}/bin/java -Dweblogic.RootDirectory=${DOMAIN_HOME} weblogic.security.Encrypt ${ADMIN_PASSWORD} >> ${DOMAIN_HOME}/servers/${SERVER_NAME}/security/boot.properties




weblogic.security.Encrypt documentation
http://download.oracle.com/docs/cd/E13222_01/wls/docs81/admin_ref/utils17.html