java - Jar is perfectly running when run via UNIX Script, but gives Null pointer when run via Crons -


i facing strange issue , able run jar fine when directly running through unix script, when same unix script triggered via crons gives me error.

my unix scirpt : myunix.ksh

/path/to/java -jar /some/path/to/myjar.jar runtimeargumentpathtomypropertyfile 

the above code if run via unix command : bash /path/to/my/script/myunix.ksh runs fine.

but when trigger script via crons ex : 9 10 * * * bash /path/to/my/script/myunix.ksh gives me null pointer exception.

my code use property file load configurable items, path pass run time argument.

the line gives me null pointer exception code access property file values. its gives me no file not found exception. seems code has found file , loaded too.

upon debugging found property object has no key value pairs when run via crons. have checked permission of files involved in process 0777. still not got solution.

here code used load properties file :

/**  * used initialise pm repository  * @param keynotcasesensitive  * @param absolutepathtomasterfile  * @param filter  * @throws gldutilexception  */ public static void initialize(boolean keynotcasesensitive, string absolutepathtomasterfile, string filter) throws gldutilexception{     if(!initialized){         map<string, string> mapoffiles = genparser.generatemapusingpropertyfile(keynotcasesensitive, absolutepathtomasterfile);         map= new linkedhashmap<string, propertymap>();         listofpropertymapnames= new arraylist<string>();          if(filter!=null){             if(keynotcasesensitive){                 filter= filter.touppercase();             }             string[] fl = filter.split(utilconstants.comma);             set<string> set = new hashset<string>(arrays.aslist(fl));             for(string key : mapoffiles.keyset()){                 for(string flt: set){                     if(keynotcasesensitive){                         key=key.touppercase();                     }                     if(key.contains(flt.trim())){                         propertymap pm = new propertymap(keynotcasesensitive, key, mapoffiles.get(key));                         map.put(key, pm);                         listofpropertymapnames.add(key);                     }                 }             }         }else{             for(string key : mapoffiles.keyset()){                 propertymap pm = new propertymap(keynotcasesensitive, key, mapoffiles.get(key));                 map.put(key, pm);                 listofpropertymapnames.add(key);             }         }         pmrepo.keynotcasesensitive=keynotcasesensitive;         pmrepo.initialized=true;     } } 

and generic parser :

    /**  *   * @param keynotcasesensitive  * @param absolutepathtofile  * @return  * @throws gldutilexception  *             utilconstants.err0001,err0002  */ public static map<string, string> generatemapusingpropertyfile(boolean keynotcasesensitive,string absolutepathtofile) throws gldutilexception {     scanner filescanner=null;     try {         filescanner = new scanner(new file(absolutepathtofile));         map<string, string> result = new linkedhashmap<string, string>();         while(filescanner.hasnextline()){             string line = filescanner.nextline();             if(line.contains(utilconstants.eq)){                 string[] pair =line.split(utilconstants.eq);                                     system.out.println(line);                 if(keynotcasesensitive){                     result.put(pair[0].trim().touppercase(), pair[1].trim());                 }else{                     result.put(pair[0].trim(), pair[1].trim());                 }              }         }         return result;     } catch (filenotfoundexception e) {         throw new gldutilexception(messageformat.format(utilconstants.err0001, absolutepathtofile), e);     }finally{         if(filescanner!=null){             filescanner.close();         }     }  } 

any direction or has faces similar issue?

i figured out. issue scanner, in generic parser. replaced scanner

public static map<string, string> generatemapusingpropertyfile(boolean keynotcasesensitive,string absolutepathtofile) throws gldutilexception {     scanner filescanner=null;     try {         filescanner = new scanner(new file(absolutepathtofile));         map<string, string> result = new linkedhashmap<string, string>();         while(filescanner.hasnextline()){ 

with bufferedreader :

public static map<string, string> generatemapusingpropertyfile(boolean keynotcasesensitive,string absolutepathtofile) throws gldutilexception {     bufferedreader br =null     try {         br= new bufferedreader (new filereader(absolutepathtofile));         map<string, string> result = new linkedhashmap<string, string>();         string line =null;         while((line=br.readline())){ 

it worked, don't know why , worked.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -