public void loadClassPath ( ) throws IOException { Class < ? > dClass = this . getClass ( ) ; CodeSource codeSrc = this . getClass ( ) . getProtectionDomain ( ) . getCodeSource ( ) ; if ( codeSrc == null ) { return ; } String codePath = codeSrc . getLocation ( ) . getPath ( ) ; if ( codePath . toLowerCase ( ) . endsWith ( ".jar" ) ) { ZipInputStream zip = new ZipInputStream ( codeSrc . getLocation ( ) . openStream ( ) ) ; while ( true ) { ZipEntry e = zip . getNextEntry ( ) ; if ( e == null ) { break ; } String fileName = e . getName ( ) ; if ( fileName . endsWith ( ".lex" ) && fileName . startsWith ( "lexicon/lex-" ) ) { load ( dClass . getResourceAsStream ( "/" + fileName ) ) ; } } } else { //now, the classpath is an IDE directory // like eclipse ./bin or maven ./target/classes/ loadDirectory ( codePath + "/lexicon" ) ; } }
load all the words from all the files under the specified class path .