PageRenderTime 117ms CodeModel.GetById 50ms app.highlight 16ms RepoModel.GetById 45ms 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
 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 */
19package mpv5.utils.files;
20
21import java.util.List;
22import java.util.StringTokenizer;
23import java.util.Vector;
24import mpv5.logging.Log;
25
26public class JarFinder {
27
28    /**
29     * Tries to localize a jar file
30     * @param nameOfJar
31     * @return
32     * @throws Exception
33     */
34    public static String getPathOfJar(String nameOfJar) throws Exception {
35        //System.setProperties("java.class.path");
36        StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
37        String jarfile = "";
38//        Log.Debug(JarFinder.class, System.getProperty("java.class.path"));
39        while (st.hasMoreTokens()) {
40
41            String token = st.nextToken();
42            if (token.indexOf(nameOfJar) > -1) {
43                jarfile = token;
44                break;
45            }
46        }
47        if (jarfile.equals("")) {
48            throw new Exception("Jar not found in classpath: " + nameOfJar);
49        } else {
50            String path = jarfile.substring(0, jarfile.indexOf(nameOfJar));
51            return path;
52        }
53    }
54
55    /**
56     *
57     * @return Th ecurrent classpath entries as list
58     */
59    public static List<String> getClassPath() {
60        StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
61        List<String> list = new Vector<String>();
62        while (st.hasMoreTokens()) {
63            list.add(st.nextToken());
64        }
65        return list;
66    }
67}