Monday, April 19, 2010
How to inject and look up custom resources in Glassfish
http://blogs.sun.com/chengfang/entry/how_to_inject_and_look
Monday, March 29, 2010
Set up a cluster (Glassfish v2.1.1) and load balancer (sjws7)
If you come accross this post by any chance, I just wanted you to know that
if you follow the below link's instructions to the dot, you will not face difficulties as its pretty straight forward.
https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html
if you follow the below link's instructions to the dot, you will not face difficulties as its pretty straight forward.
https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html
Monday, January 11, 2010
Adding an auto startup service in RH Linux 5
1.) Create a executable file.
vi filename.
2.) Add the below content to the file
#!/bin/sh
#chkconfig: 2345 80 05
#description: my service
echo "starting up"
3.)Place the scrip in etc/init.d/rc.d
4.)Make it executable: chmod a+x filename
5.)add the filename to the executing sequence using: chkconfig --add filename
Notes:
Bios -- > Master Boot Record -- > Kernel -- >Init.
read linux about startup
to see the PID of init:
ps -ef | grep init
In short, the init performs tasks that are outlined in /etc/inittab.
The folders in etc/init.d/rc.d
/etc/rc.d. there are a set of files rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6,
the system uses these files (and/or directories) to control the services to be started.
Note: to see all the auto initializing scripts
type : chkconfig --list
startup sequence in init with chkconfig
vi filename.
2.) Add the below content to the file
#!/bin/sh
#chkconfig: 2345 80 05
#description: my service
echo "starting up"
3.)Place the scrip in etc/init.d/rc.d
4.)Make it executable: chmod a+x filename
5.)add the filename to the executing sequence using: chkconfig --add filename
Notes:
Bios -- > Master Boot Record -- > Kernel -- >Init.
read linux about startup
to see the PID of init:
ps -ef | grep init
In short, the init performs tasks that are outlined in /etc/inittab.
The folders in etc/init.d/rc.d
/etc/rc.d. there are a set of files rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6,
the system uses these files (and/or directories) to control the services to be started.
Note: to see all the auto initializing scripts
type : chkconfig --list
startup sequence in init with chkconfig
Sunday, December 27, 2009
Windows Hard Drive Serial Number
public static String getSerialNumber(String drive) {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}
Execute an OS Command
public static void main (String [] args) throws IOException {
String [] Command = null;
if (System.getProperty("os.name").equals("Linux")) {
Command = new String[1];
Command[0] = "df";
}
if (System.getProperty("os.name").equals("Solaris")) {
Command = new String[2];
Command[0] = "df";
Command[1] = "-k";
}
if (Command == null) {
System.out.println("Can't find free space on this OS");
System.exit(1);
}
Process Findspace = Runtime.getRuntime().exec(Command);
BufferedReader Resultset = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));
String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
}
}
}
String [] Command = null;
if (System.getProperty("os.name").equals("Linux")) {
Command = new String[1];
Command[0] = "df";
}
if (System.getProperty("os.name").equals("Solaris")) {
Command = new String[2];
Command[0] = "df";
Command[1] = "-k";
}
if (Command == null) {
System.out.println("Can't find free space on this OS");
System.exit(1);
}
Process Findspace = Runtime.getRuntime().exec(Command);
BufferedReader Resultset = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));
String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
}
}
}
Saturday, December 26, 2009
Simple FTP Client
private void download( String ftpServer, String user, String password,
String fileName, File destination ) throws MalformedURLException,
IOException
{
if (ftpServer != null && fileName != null && destination != null)
{
StringBuffer sb = new StringBuffer( "ftp://" );
// check for authentication else assume its anonymous access.
if (user != null && password != null)
{
sb.append( user );
sb.append( ':' );
sb.append( password );
sb.append( '@' );
}
sb.append( ftpServer );
sb.append( '/' );
sb.append( fileName );
/*
* type ==> a=ASCII mode, i=image (binary) mode, d= file directory
* listing
*/
sb.append( ";type=i" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();
bis = new BufferedInputStream( urlc.getInputStream() );
bos = new BufferedOutputStream( new FileOutputStream(
destination.getName() ) );
int i;
while ((i = bis.read()) != -1)
{
bos.write( i );
}
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
else
{
System.out.println( "Input not available" );
}
}
String fileName, File destination ) throws MalformedURLException,
IOException
{
if (ftpServer != null && fileName != null && destination != null)
{
StringBuffer sb = new StringBuffer( "ftp://" );
// check for authentication else assume its anonymous access.
if (user != null && password != null)
{
sb.append( user );
sb.append( ':' );
sb.append( password );
sb.append( '@' );
}
sb.append( ftpServer );
sb.append( '/' );
sb.append( fileName );
/*
* type ==> a=ASCII mode, i=image (binary) mode, d= file directory
* listing
*/
sb.append( ";type=i" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();
bis = new BufferedInputStream( urlc.getInputStream() );
bos = new BufferedOutputStream( new FileOutputStream(
destination.getName() ) );
int i;
while ((i = bis.read()) != -1)
{
bos.write( i );
}
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
else
{
System.out.println( "Input not available" );
}
}
Thursday, December 24, 2009
Setting JAVA_HOME in RHL5
Edit /etc/profile.
JAVA_HOME=/usr/java/jre1.6.0_17
export JAVA_HOME
PATH=$ORACLE_HOME/bin:$JAVA_HOME/bin:$PATH
export PATH
JAVA_HOME=/usr/java/jre1.6.0_17
export JAVA_HOME
PATH=$ORACLE_HOME/bin:$JAVA_HOME/bin:$PATH
export PATH
Subscribe to:
Posts (Atom)