简体   繁体   中英

Could not load class when executed with -cp option of `'hadoop classpath`

my question is very close to this one, which is already answered. Could not load class when executed with -cp option

However, the situation is slightly different

$ javac -cp `hadoop classpath` GrabHDFSBlockInfo.java 
$ java -cp `hadoop classpath` GrabHDFSBlockInfo 
 Error: Could not find or load main class GrabHDFSBlockInfo
$ ls GrabHDFSBlockInfo*
 GrabHDFSBlockInfo.class  GrabHDFSBlockInfo.java

so I'd like to use the shortcut of hadoop classpath in this case.

many thanks for your help

Demai


edit: thanks for everyone's help. Since hadoop classpath doesn't change much on my cluster. I eventually change my .bashrc, by setup a var with expanded classpath padding ':.' then, just use $ java -cp $classpath GrabHDFSBlockInfo

One of the known problems of hadoop classpath is that it contains wildcards. As a result of that, the hadoop libraries cannot be loaded properly. As a workaround, try expanding the wildcards, replacing them with sequences of jars located there. It will most probably help.

A little zsh script for a similar purpose (though I simply updated existing CLASSPATH there):

classpath=`hadoop classpath | tr ':' ' ' | sort | uniq`
for file in ${=~classpath}(N)
do
  export CLASSPATH=$CLASSPATH:$file
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM