-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/org/puc/rio/inf1636/hglm/war/viewcontroller/ResourceUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.puc.rio.inf1636.hglm.war.viewcontroller; | ||
|
||
import java.net.URL; | ||
|
||
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader; | ||
|
||
public class ResourceUtil { | ||
|
||
//from http://stackoverflow.com/questions/3861989/preferred-way-of-loading-resources-in-java | ||
public static URL getResource(String resource){ | ||
|
||
URL url ; | ||
|
||
//Try with the Thread Context Loader. | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
if(classLoader != null){ | ||
url = classLoader.getResource(resource); | ||
if(url != null){ | ||
return url; | ||
} | ||
} | ||
|
||
//Let's now try with the classloader that loaded this class. | ||
classLoader = Loader.class.getClassLoader(); | ||
if(classLoader != null){ | ||
url = classLoader.getResource(resource); | ||
if(url != null){ | ||
return url; | ||
} | ||
} | ||
|
||
//Last ditch attempt. Get the resource from the classpath. | ||
return ClassLoader.getSystemResource(resource); | ||
} | ||
} |