Tuesday 15 December 2009

Maven


Apache Maven

Setup maven:

  1. Create a JAVA_HOME system variable.
  2. Create an M2_HOME system variable.
  3. Add %JAVA_HOME%\bin;%M2_HOME%\bin; to your system path.
  4. (Optional) Create a %MAVEN_OPTS% system variable. This variable name specified as java options in mvn.bat and mvn.sh. "-Xms512m -Xmx6024m"

Set configurations:

Configuration file (setting.xml) cab be found in two places:

  • The Maven install: $M2_HOME/conf/settings.xml (Global setting)
  • A user’s install: ${user.home}/.m2/settings.xml (User setting)

If both files configured then configuration in both will be merged and user setting will override global setting. 

Set the location for local maven repository:

Default local repository configuration details in setting.xml.

 

Include the following to entry to point to the local repository C:/maven/m2repository


/maven/m2repository








Tuesday 24 November 2009

ORA-29541: class could not be resolved

Load/Drop java

dropjava -verbose -user test/test@test_1  test.jar
loadjava -resolve -verbose -grant public -user test/test@test_1  test.jar


loadjava -verbose -user test/test@test_1 JavaTest.class ??
loadjava -verbose -user test/test@test_1 c:\JavaTest.java


CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "JavaTest" AS
   public class JavaTest {
   public static String sayHello (String  name) {
   return "Hello, " + name+ "!";
     }
  };



check the status of object

select * from all_objects where object_type like '%JAVA%';

Eclipse Java Color Themes

http://srand2.blogspot.com/2009/08/eclipse-color-themes.html

Monday 23 November 2009

Enabling or Disabling Directory Listings using web.xml

http://wiki.metawerx.net/wiki/EnablingOrDisablingDirectoryListingsUsingWeb.xml


Adding context

add an entry to conf/sever.xml
context
      - path  = "/test"
      - reloadabe = "false"
      - docBase="/homt/test/output"
       -workDir="
/homt/test/output/workdir"             

Tuesday 10 November 2009

Example for bind variable usage in SqlPlus

Example sql code
*Declare DATE variable as bind variable in SQL Plus*
 
 
set linesize 132;
set timing on;
set linesize 255;
set pagesize 5000;
set echo on;
set heading on;
set serveroutput on;
 
 
variable type varchar2(100);
execute :type := 'S';
 
variable startdate varchar2(21);
execute :startdate := '01/10/2013_00:00:00';
 
variable enddate varchar2(21);
execute :enddate := '01/10/2013_01:00:00';
 
variable testid number;
execute :testid := 6154;
 
set autotrace on exp stat;
set autotrace traceonly exp stat;
 
select count(*) as y0_
  from TEST_TABLE this_
 where this_.TEST_ID = :testid
   and this_.TYPE = :inctype
   and this_.C_TIME_LOCAL >= to_date(:startdate,'dd/mm/yyyy_hh24:mi:ss');
   and this_.C_TIME_LOCAL <= to_date(:enddate,'dd/mm/yyyy_hh24:mi:ss');





-- Check Execution Plan details
select sql_id, child_number, s.*
  from gv$sql s
 WHERE upper(SQL_FULLTEXT) like '%SUMMARY%'
 order by last_active_time desc;
 
SELECT * FROM TABLE(dbms_xplan.display_cursor('b250w5cxy46va', 0,'ADVANCED'));
SELECT * FROM table(DBMS_XPLAN.DISPLAY_AWR('fywm6bbj5s1zn'));
SELECT * FROM TABLE(dbms_xplan.display_cursor('287h80pjaugst'));
SELECT * FROM TABLE(dbms_xplan.display_cursor('dqkapjswv169p', 0));
SELECT * FROM TABLE(dbms_xplan.display_cursor('6z5c8yaf3m1gt', 0,'ADVANCED'));
 
set autotrace on exp stat;
set autotrace traceonly exp stat;
 
EXPLAIN PLAN FOR SQL_STATEMET;
@?/RDBMS/ADMIN/UTLXPLS
select * from table(dbms_xplan.display);
 
 
 select sql_id, child_number, s.*
  from gv$sql s
 WHERE upper(SQL_FULLTEXT) like '%V_INCIDENT_SIGHTING_SUMMARY%'
 order by last_active_time desc;
select sql_text, v.sql_id, name, value_string, datatype_string
  from v$sql_bind_capture vbc
  join v$sql v
 using (hash_value)
 where v.sql_id in ('frmxr4w3tb9wv', 'dqkapjswv169p', '61g3km3x621wt');
SELECT sql_id, name, value_string, datatype_string
  from v$sql_bind_capture
 where sql_id in ('frmxr4w3tb9wv', 'dqkapjswv169p');
SELECT * FROM v$sql_bind_capture WHERE sql_id = 'frmxr4w3tb9wv';
SELECT * FROM v$sql_bind_capture WHERE sql_id = '61g3km3x621wt';
 
SELECT *
  FROM v$sql_bind_capture
 WHERE sql_id in ('dqkapjswv169p', 'frmxr4w3tb9wv', '61g3km3x621wt');

Monday 9 November 2009

X forwarding. : Error - xterm Xt error: Can't open display:

ERROR:
connection to "host23.0" refused by server
Xlib: Client is not authorized to connect to Server
xhost:  unable to open display "host23.0"

xterm Xt error: Can't open display:

You should enable X forwarding. Note that should be enabled in ssh daemon settings.

$ ssh -X user@host


Link
http://www.linuxquestions.org/questions/linux-software-2/xterm-xt-error-cant-open-display-697237/

Tuesday 27 October 2009

JAXB & Ant : package-info.java compilation problem of JAXB generated classes.

 package-info.class not generated

1.Generate the class
  xjc -p test.xsd -d C:/workspace/Test/src
2. Compile the project . package-info.class is generated.
3. Then call the clean task to remove .class files and rebuild the project. package-info.class is not generated.


Note on package-info.java from Ant Manual [http://ant.apache.org/manual/CoreTasks/javac.html]

 package-info.java files were introduced in Java5 to allow package level annotations. On compilation, if the java file does not contain runtime annotations, there will be no .class file for the java file. Up to Ant 1.7.1, when the task is run again, the task will try to compile the package-info java files again.

In Ant 1.7.1 the package-info.java will only be compiled if:

   1. If a package-info.class file exists and is older than the package-info.java file.
   2. If the directory for the package-info.class file does not exist.
   3. If the directory for the package-info.class file exists, and has an older modification time than the the package-info.java file. In this case will touch the corresponding .class directory on successful compilation.
  


Related Links
http://ant.apache.org/manual/CoreTasks/javac.html
http://article.gmane.org/gmane.comp.jakarta.ant.devel/52586
http://www.javalinux.it/wordpress/?p=261

Monday 26 October 2009

JAVA Compiler error : class file has wrong version 49.0, should be 48.0

Compiler error message :

    [javac] class file has wrong version 49.0, should be 48.0
    [javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
    [javac] import com.common.dao.QueueDAO;
    [javac]                         ^
    [javac] 1 error

Reason :

Java 1.4 creates class files labeled with version 48.0
Java 1.5 creates class files labeled with version 49.0
Check the java compiler versions


Related links :
http://forums.sun.com/thread.jspa?threadID=644158
http://www.dreamincode.net/forums/showtopic49155.htm

Thursday 15 October 2009

How does log4j load the config files ?

Add -Dlog4j.debug to the command line.


trace file :

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@11b86e7.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@11b86e7 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@11b86e7.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@11b86e7 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
ControlListener Created





Links :
http://jaitechwriteups.blogspot.com/2006/07/know-how-log4j-tries-to-configure.html
http://jaikiran.wordpress.com/2006/07/05/i-get-log4jwarn-no-appenders-could-be-found-for-logger-message-2/
 

Friday 2 October 2009

Eclips Shortcut Key

       I do not have patient to browse through the files, I always look for shortcuts and customize the editor shortcut keys as I wish.

You can assign or edit the shortcut key binding.
Goto , Window  --> Preferences --> General --> Keys, Just play around with that window.

List of shortcut keys : CTRL+SHIFT+L


List of shortcut key list

Open a Resource : Ctrl+Shift+Y
Open a Type:        Ctrl+Shift+T

Go to Method :     Ctrl+O , Shift+O,O
Go to Line:           Ctrl+L

Lower Case:        Ctrl+Shift+Y
Upper Case:        Ctrl+Shift+X

Expand:              Ctrl+Numpad_Add
Expand All:         Ctrl+Numpad_Multiply
Collapse:            Ctrl+Numpad_Subtract
Collapse All:       Ctrl+Shift+Numpad_Divide

Friday 25 September 2009

ORACLE Error : ORA-00972: identifier is too long

Check the following link

http://www.dba-oracle.com/sf_ora_00972_identifier_is_too_long.htm

Monday 21 September 2009

How to email the file attachment from unix ?

/usr/bin/uuencode daily.zip daily.zip | /usr/bin/mailx -s "Daily Report" xyz@yahoo.com


Ref Link:
http://www.cyberciti.biz/faq/howto-unix-sending-files-as-mail-attachments/

How to change date format in oracle?

ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY hh:mi:ss AM';


Ref links:

http://www.dba-oracle.com/sf_setting_parameters_tips.htm
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:351017764854

Tuesday 15 September 2009

How to Execute SQL Scripts using sh file ?


sqlplus $DBUSERNAME/$DBPASSWORD@$DBNAME @/home/test/query/test.sql

Eclipse Warning : "The type MobTest collides with a package"

Reason : The package name is same as class name.

Friday 11 September 2009

Eclipse Error : Access restriction:The method ..

Error message ..

Access restriction: The method createJPEGEncoder(OutputStream) from the type JPEGCodec is not accessible due to restriction on required library C:\Program Files\Java\jdk1.6.0_11\jre\lib\rt.jar   

Access restriction: The method getDefaultJPEGEncodeParam(BufferedImage) from the type JPEGImageEncoder is not accessible due to restriction on required library C:\Program Files\Java\jdk1.6.0_11\jre\lib\rt.jar   

Access restriction: The method setJPEGEncodeParam(JPEGEncodeParam) from the type JPEGImageEncoder is not accessible due to restriction on required library C:\Program Files\Java\jdk1.6.0_11\jre\lib\rt.jar    ImageUtil.java   

Solution

Go to Project properties -->Java Compiler --> Errors Warnings, Then enable project specific settings,
 Expand Deprecated and restrited APIs category
  -Forbidden reference (acess rule) , Change to warning or ignore.

Spell checker for Eclipse

Create the text file or Down load this file

Edit Eclipse Preferences:
   - Window -> Preferences -> General-> Editors-> Text Editors-> Spelling
   - Browse to the text file or downloaded file.


Click on the word and type CTRL+1, It will show context menu in eclipse editor.You can click your option.

Ref
Eclipse: Catch Those Spelling Errors

Eclipse Error : "Java compiler level does not match the version of the installed Java project facet"

Go o Project ->Properties -> Project Facets panel and set java facet version to match the java compiler compliance level.

How to increase java heap size in Maven2?

Set an environment variable to increase the heap size.


set MAVEN_OPTS=-Xmx1024m

How to increase java heap size in NetBeans?

 Edit the file NETBEANS_HOME/etc/netbeans.conf. Current conf file contents given below

netbeans_default_options="-J-Dorg.glassfish.v3.installRoot=\"C:\Program Files\sges-v3-prelude\" -J-Dcom.sun.aas.installRoot=\"C:\Sun\AppServer\" -J-client -J-Xss2m -J-Xms32m -J-Xmx1024m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true --fontsize 14 --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"


Description
--fontsize 14  [to change the default font size in editor]
--laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel  [to change the Look And Feel]
Some other look an feel values,
javax.swing.plaf.metal.MetalLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel

How to increase java heap size in Eclipse?

Add following entries to  eclipse.ini file.Current eclipse.int contents given below

-vmargs
-Xms512m  [minimum memory ]
-Xmx1024m  [maximum memory]
-Duser.name=Thillakan Sabanayakam  [Eclipse uses you OS user name in the @author java doc tag for default ]


Contents
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256M
-clean
-framework
plugins\org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024m
-Duser.name=Thillakan Sabanayakam

Explore process Information in unix

Each process has an entry in the /proc filesystem identified by its PID. The following are the important files in /proc directory:
  • pid/cmdline contains the command that was used to start the process (using null characters to separate the arguments).
  • /proc/pid/cwd contains a link to the current working directory of the process.
  • /proc/pid/environ contains a list of the environment variables that the process has available.
  • /proc/pid/exe contains a link to the program that is running in the process.
  • /proc/pid/fd/ is a directory containing a link to each of the files that the process has open.
  • /proc/pid/mem contains the memory contents of the process.
  • /proc/pid/stat contains process status information.
  • /proc/pid/statm contains process memory usage information. 
  • /proc/pid/lwp contains the threads running in the process with the process id

Commands :
ls -l /proc/pid/fd | wc -l
ls -l /proc/pid/lwp | wc -l

Thursday 10 September 2009

How to insert single or double quote into Oracle DB?

 Using q-quote string syntax, It can be done

Example :

INSERT INTO T(test) 
values (q'[single's quote and "double" quotes]');

Monday 7 September 2009

How To Override Hibernate Configuration Settings?

 The following code segment will override the some properties. [hibernate.connection.driver_class, hibernate.connection.url ,hibernate.connection.url, hibernate.connection.password]


    public static void createSessionFactory(String driverclass,String url, String username, String password, String configFile) throws HibernateException {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        Configuration cfg = new AnnotationConfiguration().addResource(configFile);
        cfg.configure(configFile);
        cfg.setProperty("hibernate.connection.driver_class", driverclass);
        cfg.setProperty("hibernate.connection.url", url);
        cfg.setProperty("hibernate.connection.url", username);
        cfg.setProperty("hibernate.connection.password", password); 
        sessionFactory = cfg.buildSessionFactory();
    }

       Hibernate configuration files properties used in following implementation.

    public static void createSessionFactory(String driverclass,String url, String username, String password, String configFile) throws HibernateException {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        Configuration cfg = new AnnotationConfiguration().addResource(configFile);     
        cfg.setProperty("hibernate.connection.driver_class", driverclass);
        cfg.setProperty("hibernate.connection.url", url);
        cfg.setProperty("hibernate.connection.url", username);
        cfg.setProperty("hibernate.connection.password", password); 
        cfg.configure(configFile);
        sessionFactory = cfg.buildSessionFactory();
    }

Thursday 3 September 2009

How To Add Your Linkedin Profile Button To Your Blogger Blog

Check the following links..
http://smallworkarounds.blogspot.com/2008/11/adding-linkedin-button-to-blogger-or.html
http://salesittech.blogspot.com/2009/02/include-your-linkedin-button-in-blogger.html

Friday 28 August 2009

Optimize Firefox Speed

  You can use pipelinning to speed up page load.Which allows Firefox to load multiple things at once.

    * Type “about:config” into the address bar and hit return.
    * Type “network.http.*pipe” in the filter field, and change the following settings.       
    (Double-click on them to change them):
    * Set “network.http.pipelining” to “true
    * Set “network.http.proxy.pipelining” to “true
    * Set “network.http.pipelining.maxrequests” to "8".




Helpful Links
http://egonitron.com/2007/05/25/the-truth-about-the-firefox-pipelining-trick/

Wednesday 26 August 2009

Packge once. Deploy everywhere

I was looking for a software to bundle my application as one installer. So it can deploy it any where. I found open source product IzPack. It requires only a Java virtual machine to deploy.

IzPack : http://izpack.org/

There are some commercial product available, Following products are used to create windows installer (msi) package.

InstallShield
Advanced Installer

Some more free tools ..

Windows Installer XML (WiX)
InstEd
NSIS

Saturday 22 August 2009

Eclipse Plug-In - Easy Explorer

Easy Explorer is a very useful plug in, Which helps you to browse resources with the native Operating system explorer. In the Eclipse, select a file, right-mouse click, and select the 'Easy Explore...'

I am using Galileo & easy-explore-1.0.4.

Image Magnification Testing :(






Plug-In details links

Easy Explorer Home
Download Plug-in

Tuesday 2 June 2009

Daemon Thread in Java


  • Any thread created by main thread is by default user thread. Because when a new thread is created it inherits the daemon status of its parent. (Check output result)
  • Need to explicitly set daemon (setDaemon(true)) but this can only be called before starting thread otherwise it will throw IllegalThreadStateException if the related thread already started.  (Check output result) 
  • Normal thread and daemon threads differ in what happens when they exit. When the JVM halts any remaining daemon threads are abandoned: Finally blocks are not executed. Stacks are not unwound and JVM just exits. (Check output result)
  •  Main different is that as soon as all user thread finish execution java program or JVM terminates itself, JVM doesn't wait for daemon thread to finish there execution. As soon as last non daemon thread finished JVM terminates no matter how many Daemon thread exists or running inside JVM. (Check output result)


Sample Code

public class DaemonTest {

    public static void main(String[] args) {
        System.out.println("Entering main Method");
        WorkerThread wt = new WorkerThread();

        // When false, (i.e. when it's a user thread),
        // the Worker thread continues to run. finally block will run
        // When true, (i.e. when it's a daemon thread),
        // the Worker thread terminates when the main thread terminates. finally block doesn't run
        /** Set daemon flag */
        wt.setDaemon(true);
        wt.start();
        try {
            Thread.sleep(7500);
            System.out.println("Main Thread wake up");
        } catch (InterruptedException e) {
        }
        System.out.println("Main Thread ending");
    }

}

class WorkerThread extends Thread {

    public void run() {
        System.out.println("Entering WorkerThread run method IsDaemon:" + Thread.currentThread().isDaemon());
        try {
            System.out.println("In run Method: currentThread() is" + Thread.currentThread());
            int count = 0;
            while (count < 10) {
                System.out.println("Hello from Worker " + count++);
                try {
                    sleep(2000);
                } catch (InterruptedException e) {
                }
                System.out.println("In run method: woke up again");
            }
        } finally {
            System.out.println("NOTE : Leaving Worker run Method running finally block");
        }
    }
}


Output: User thread / Non-Daemon thread
Entering main Method
Entering WorkerThread run method IsDaemon:false
In run Method: currentThread() isThread[Thread-0,5,main]
Hello from Worker 0
In run method: woke up again
Hello from Worker 1
In run method: woke up again
Hello from Worker 2
In run method: woke up again
Hello from Worker 3
Main Thread wake up
Main Thread ending
In run method: woke up again
Hello from Worker 4
In run method: woke up again
Hello from Worker 5
In run method: woke up again
Hello from Worker 6
In run method: woke up again
Hello from Worker 7
In run method: woke up again
Hello from Worker 8
In run method: woke up again
Hello from Worker 9
In run method: woke up again
NOTE : Leaving Worker run Method running finally block

Process finished with exit code 0



Output: Daemon thread
Entering main Method
Entering WorkerThread run method IsDaemon:true
In run Method: currentThread() isThread[Thread-0,5,main]
Hello from Worker 0
In run method: woke up again
Hello from Worker 1
In run method: woke up again
Hello from Worker 2
In run method: woke up again
Hello from Worker 3
Main Thread wake up
Main Thread ending

Process finished with exit code 0



Output: Setting daemon flag after starting thread
Entering main Method
Exception in thread "main" java.lang.IllegalThreadStateException
 at java.lang.Thread.setDaemon(Thread.java:1275)
 at com.java.concurrency.c1.DaemonTest.main(DaemonTest.java:16)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Entering WorkerThread run method IsDaemon:false
In run Method: currentThread() isThread[Thread-0,5,main]
Hello from Worker 0
In run method: woke up again
Hello from Worker 1
In run method: woke up again
Hello from Worker 2
In run method: woke up again
Hello from Worker 3
In run method: woke up again
Hello from Worker 4
In run method: woke up again
Hello from Worker 5
In run method: woke up again
Hello from Worker 6
In run method: woke up again
Hello from Worker 7
In run method: woke up again
Hello from Worker 8
In run method: woke up again
Hello from Worker 9
In run method: woke up again
NOTE : Leaving Worker run Method running finally block

Process finished with exit code 1


NOTES:
Daemon thread which runs in background and mostly created by JVM for performing background tasks such as

  • Garbage collection
  • Performing asynchronous I/O task. ????
  • Listening for incoming connections ????
  • Collecting statistics and performing the status monitoring tasks
    • Sending and receiving network heartbeats , supplying the service monitoring tools
  • House keeping jobs


Monday 16 March 2009

Things to note when desinging a module

Some points to consider when we designing or implementing application. These points will helpful to diagnose or fix issues in production environment. Will update whenever my code bite back :)
  1. Externalizing configuration values in database or .properties or XML files.
  2. Testing the application with the volume of data in production.
  3. Set proper timeout functions 
  4. Set limit to retry functions to connect to third party or external services 
  5. Browser compatibility checking
  6. Proper database design Column to indicate created, updated time and user details, Active or delete flag
  7. Security