Here you can find the source of getURLFromPath(String jarPath)
Parameter | Description |
---|---|
jarPath | The path that represents a URL |
Parameter | Description |
---|---|
IllegalArgumentException | is something goes wrong |
public static URL getURLFromPath(String jarPath)
//package com.java2s; /*/* www. j a v a2 s . c o m*/ * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ import java.net.MalformedURLException; import java.net.URL; public class Main { /** * get the URL from a given path string * * @param jarPath The path that represents a URL * * @return The resolved URL reference * * @throws IllegalArgumentException is something goes wrong */ public static URL getURLFromPath(String jarPath) { URL jarUrl; try { //is it an url jarUrl = new URL(jarPath); } catch (MalformedURLException e) { try { //consider it as a file path jarUrl = new URL("file:" + jarPath); } catch (MalformedURLException ee) { throw new IllegalArgumentException("Unable to find jar:" + jarPath, ee); } } return jarUrl; } }