static {
/**
* 配置文件变量
*/
ResourceBundle rb = null;
try {
rb = ResourceBundle.getBundle("ansj_library");
} catch (Exception e) {
try {
File find = FileFinder.find("ansj_library.properties", 1);
if (find != null && find.isFile()) {
rb = new PropertyResourceBundle(
IOUtil.getReader(find.getAbsolutePath(), System.getProperty("file.encoding")));
LIBRARYLOG.info(
"load ansj_library not find in classPath ! i find it in {} make sure it is your config!",
find.getAbsolutePath());
}
} catch (Exception e1) {
LIBRARYLOG.warn("not find ansj_library.properties. and err {} i think it is a bug!", e1.getMessage());
}
}
if (rb == null) {
try {
rb = ResourceBundle.getBundle("library");
} catch (Exception e) {
try {
File find = FileFinder.find("library.properties", 2);
if (find != null && find.isFile()) {
rb = new PropertyResourceBundle(
IOUtil.getReader(find.getAbsolutePath(), System.getProperty("file.encoding")));
LIBRARYLOG.info(
"load library not find in classPath ! i find it in {} make sure it is your config!",
find.getAbsolutePath());
}
} catch (Exception e1) {
LIBRARYLOG.warn("not find library.properties. and err {} i think it is a bug!", e1.getMessage());
}
}
}
DIC.put(DIC_DEFAULT, "library/default.dic");
if (rb == null) {
LIBRARYLOG.warn("not find library.properties in classpath use it by default !");
} else {
for (String key : rb.keySet()) {
if (key.equals("dic")) {
DIC.put(key, rb.getString(key));
} else if (key.equals("crf")) {
CRF.put(key, rb.getString(key));
} else if (key.startsWith("dic_")) {
if (DIC.containsKey(key)) {
LIBRARYLOG.warn("{} dic config repeat definition now overwrite it !", key);
}
DIC.put(key, rb.getString(key));
} else if (key.startsWith("crf_")) {
if (CRF.containsKey(key)) {
LIBRARYLOG.warn("{} crf config repeat definition now overwrite it !", key);
}
CRF.put(key, rb.getString(key));
} else {
try {
Field field = MyStaticValue.class.getField(key);
field.set(null, ObjConver.conversion(rb.getString(key), field.getType()));
} catch (NoSuchFieldException e) {
LIBRARYLOG.error("not find field by {}", key);
} catch (SecurityException e) {
LIBRARYLOG.error("安全异常", e);
} catch (IllegalArgumentException e) {
LIBRARYLOG.error("非法参数", e);
} catch (IllegalAccessException e) {
LIBRARYLOG.error("非法访问", e);
}
}
}
}
}
此静态块用于加载ansj配置文件。
我不明白的是,为什么在WEB-INF下面建立classes目录,其中放properties配置文件,solr日志却报错说“classpath”目录下没有配置文件。