Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. parent
  2. ...pom.xml
  3. ...servlet-app
  4. ......pom.xml ( specifies simple-lib as a dependency )
  5. ...simple-lib
  6. ......src/main/resources/config.properties
  7. ......src/main/java/package1/Config.java
  8. ......src/main/java/package1/HelloQuartzJob.java
  9.  
  10. public class Config{
  11.  
  12. static final String PROPERTILES_FILE = "config.properties";
  13. static Properties props;
  14. static{
  15. log.info("Loading Config properties from {}", PROPERTILES_FILE);
  16. props = new Properties();
  17.  
  18. try {
  19. InputStream is = ClassLoader.getSystemResourceAsStream(PROPERTILES_FILE);
  20. if (is == null) {
  21. log.info("Loading through ClassLoader as root");
  22. is = ClassLoader.getSystemResourceAsStream("/"+PROPERTILES_FILE);
  23. }
  24. if (is == null) {
  25. log.info("Loading through Config.class. root");
  26. is = Config.class.getResourceAsStream("/"+PROPERTILES_FILE);
  27. }
  28. if (is == null) {
  29. log.info("Loading through Config.class. relative");
  30. is = Config.class.getResourceAsStream(PROPERTILES_FILE);
  31. }
  32. if( is == null ) {
  33. log.info("Thread class loader root");
  34. is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/"+PROPERTILES_FILE);
  35. }
  36. props.load(is);
  37. } catch (Throwable e) {
  38. log.error("Config properties loading error ", e);
  39. throw new RuntimeException(e);
  40. }
  41. }
  42. }
  43.  
  44. InputStream is = ClassLoader.getSystemResourceAsStream(PROPERTILES_FILE);
  45.  
  46. InputStream is = Config.class.getClassLoader().getResourceAsStream(PROPERTILES_FILE);
  47.  
  48. is = ClassLoader.getSystemResourceAsStream("/"+PROPERTILES_FILE);
  49.  
  50. is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/"+PROPERTILES_FILE);
  51.  
  52. String url = Config.class.getClassLoader().getResource("config.properties");
  53. InputStream is = Config.class.getClassLoader().getResourceAsStream("config.properties");
  54.  
  55. String url = getClass().getClassLoader().getResource("config.properties");
  56. InputStream is = getClass().getClassLoader().getResourceAsStream("config.properties");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement