So I am building a utility JAR for an EAR and I have a class which provides static methods which need an XML string. I am embedding an XML file as a resource in my JAR and I read it at class initialization time in a static block:
static{
try {
base = IOUtils.toString(CartSessionFactory.class.getResourceAsStream("/createcartTemplate.xml"));
if(base==null){
throw new Exception("createcartTemplate.xml not found as a resource");
}
//check the file correctness
//[...]
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
A fellow coder told me he was horrified at that design but could not explain clearly why (but recommanded making a Singleton instead). It seems to work though. Is it bad design and why?