PageRenderTime 20ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/utils/files/JarFinder.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 67 lines | 32 code | 5 blank | 30 comment | 5 complexity | 70658c9e54eafd42f3ca5da19973695d MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. *
  3. * * This file is part of YaBS.
  4. * *
  5. * * YaBS is free software: you can redistribute it and/or modify
  6. * * it under the terms of the GNU General Public License as published by
  7. * * the Free Software Foundation, either version 3 of the License, or
  8. * * (at your option) any later version.
  9. * *
  10. * * YaBS is distributed in the hope that it will be useful,
  11. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * * GNU General Public License for more details.
  14. * *
  15. * * You should have received a copy of the GNU General Public License
  16. * * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package mpv5.utils.files;
  20. import java.util.List;
  21. import java.util.StringTokenizer;
  22. import java.util.Vector;
  23. import mpv5.logging.Log;
  24. public class JarFinder {
  25. /**
  26. * Tries to localize a jar file
  27. * @param nameOfJar
  28. * @return
  29. * @throws Exception
  30. */
  31. public static String getPathOfJar(String nameOfJar) throws Exception {
  32. //System.setProperties("java.class.path");
  33. StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
  34. String jarfile = "";
  35. // Log.Debug(JarFinder.class, System.getProperty("java.class.path"));
  36. while (st.hasMoreTokens()) {
  37. String token = st.nextToken();
  38. if (token.indexOf(nameOfJar) > -1) {
  39. jarfile = token;
  40. break;
  41. }
  42. }
  43. if (jarfile.equals("")) {
  44. throw new Exception("Jar not found in classpath: " + nameOfJar);
  45. } else {
  46. String path = jarfile.substring(0, jarfile.indexOf(nameOfJar));
  47. return path;
  48. }
  49. }
  50. /**
  51. *
  52. * @return Th ecurrent classpath entries as list
  53. */
  54. public static List<String> getClassPath() {
  55. StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
  56. List<String> list = new Vector<String>();
  57. while (st.hasMoreTokens()) {
  58. list.add(st.nextToken());
  59. }
  60. return list;
  61. }
  62. }