Thursday, February 15, 2018

java: Invalid argument on unix

I was trying to install JDK on Solaris.

I installed JDK for Solaris X64 avoiding SPARC installation as I did not know what is SPARC ;-)

once installed, I was getting error :
java: Invalid argument 

Soon I found that this error comes if java installation is of wrong type.

Find your correct type of JDK by checking the system type by
uname -p

Process ID - PID of the used port in Solaris, Unix

In Unix/Linux PID of the port used can be found by

netstat --listen
OR
netstat -l
OR
netstat -aun
OR
netstat -an|grep LISTEN    will give you list of opened ports


Problem is with Solaris (10). There is no direct command to find the same.

I found following links to execute shell scripts:
https://blogs.oracle.com/opengrok/get-application-pid-listening-on-a-network-port-in-solaris-aka-netstat-npl-in-solaris

https://geekflare.com/check-pid-using-port-number-solaris/

But I could not executed any of these and finally found following:

PORT=19028; for PID in /proc/*; do pfiles ${PID} |grep "port: ${PORT}" && echo ${PID}; done

you may have to search for AF_INET

If you have ROOT permission, then you may find any port's PID else it can help you to find the port at least opened by you.

Tuesday, February 28, 2017

Oracle driver for maven

To add dependency in maven for oracle driver ojdbc6 and onwards, is not available in central repository.

You have to download the driver from oracle site and then install manually for maven.

 mvn install:install-file -Dfile=C:/workSoftwares/ojdbc6.jar  -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

and then add dependency in pom.xml



com.oracle
ojdbc6
11.2.0.2.0

Tuesday, February 21, 2017

logback config flie as environment parameter

logback configuration file can be passed as environment parameter to SLF as

-Dlogging.config=file:"C:\mytemp\logback.xml"

Friday, February 17, 2017

log4j2 sample configuration file

Following is the sample n simple configuration file (file name MUST be log4j2.xml)

<?xml version="1.0" encoding="UTF-8"?>


<Configuration>
<Properties>
<Property name="ivr-log-path">C:/mytemp/ivrLogs</Property>
</Properties>

  <Appenders>
   <Console name="console" target="SYSTEM_OUT">
    <PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
   </Console>
    <RollingFile  name="rollingFile" filename="${ivr-log-path}/myexampleRK.log" filepattern="${ivr-log-path}/myexampleRK_fargo.log.%i">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 KB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
    </RollingFile>
  </Appenders>

  <Loggers>
        <Root level="debug">
            <AppenderRef ref="rollingFile" />
            <AppenderRef ref="console" />
            <!-- Use FLOW to trace down exact method sending the msg -->
            <!-- <AppenderRef ref="FLOW" /> -->
        </Root>
   </Loggers>
</Configuration>


PS: used http://codebeautify.org/xml-escape-unescape for encoding XML

Tuesday, February 07, 2017

How to fix Eclipse Java Virtual Machine Launcher Error?

If you play around little bit jdk/jre directories then one day you may encounter Eclipse Java Virtual Machine Launcher error.


Eclipse is not  finding the JRE to launch the eclipse.

Following has all the information to one needs for eclipse.ini file that initializes the eclipse.
http://wiki.eclipse.org/Eclipse.ini

To run the eclipse set the -vm option in the initializer file.

Example:  
-vm

C:\PROGRA~1\Java\jdk1.8.0_121\bin\javaw.exe


Thursday, February 02, 2017

Maven Path Properties list

Following is list of maven path properties from https://cwiki.apache.org/confluence/display/MAVEN/Maven+Properties+Guide

This page extracts a few classical values:
  • ${project.basedir} 
    • This references to the root folder of the module/project (the location where the current pom.xml file is located)
POM properties referencing useful build locations, with default values defined in the Super POM:
  • ${project.build.directory}
    • This represents by default the target folder.
  • ${project.build.outputDirectory}
    • This represents by default the target/classes folder.
  • ${project.build.testOutputDirectory}
    • This represents by default the target/test-classes folder.
  • ${project.build.sourceDirectory}
    • This represents by default the src/main/java folder.
  • ${project.build.testSourceDirectory}
    • This represents by default the src/test/java folder.
You can use further properties like the following:
  • ${project.build.finalName}
    • This is by default defined as ${project.artifactId}-${project.version}.
  • ${project.version}
    • This can be used at locations where you have to write a literal version otherwise, in particular if you are in a multi-modules build for inter modules dependencies.
User Settings
The settings.xml elements could be referenced by using things like this (see also at the Super POM):
  • ${settings.localRepository}
    • which references the location of the local repository. This is by default ${home}/.m2/repository.

Monday, October 29, 2012

Static class loader

I was just wandering, how to identified class loader for static block.

We can find the class loader for a class by using following :
        this.getClass().getClassLoader()

So here is small piece of code to find the classloader for static block.


class Loader {
   // static final String theName = "The Loader";
   static String s = "";
    static {
         try {
Class c = Class.forName(Loader.class.getName());
s = c.getClassLoader().toString();
} catch (ClassNotFoundException e) {
}
        System.out.println("Loader.static  : " + s);
        System.out.println("Loader.static Loader : " + ClassLoader.getSystemClassLoader() ) ;
    }


    Loader() {
        System.out.println("Loader.Loader()");
    }
} // End of Loader

public class ClasLoaderTest {
    static {
        System.out.println( "Test.static");
    }
    ClasLoaderTest() {
Loader l = new Loader();
        System.out.println( "Test.Test()");
    }
    public static void main( String [] args ) {
        System.out.println( "Test.main");
        ClasLoaderTest t = new ClasLoaderTest();
t.myMeth();
        System.exit(0);
    }

    public void myMeth() {
        String s = this.getClass().getClassLoader().toString();
        System.out.println( "Class Loader " + s);

}

}// End of ClasLoaderTest


Above sample code is taken from http://www.engfers.com/code/static-initializer-block/ .
Please let me know if there is any copy right violation or any other infringements.

Output is following:


Test.static
Test.main
Loader.static  : sun.misc.Launcher$AppClassLoader@fabe9
Loader.static Loader : sun.misc.Launcher$AppClassLoader@fabe9
Loader.Loader()
Test.Test()
Class Loader sun.misc.Launcher$AppClassLoader@fabe9