How can I see if I'm running from JAR?  
Author Message
giangiammy@gmail.com





PostPosted: 2006-7-4 23:22:00 Top

java-programmer, How can I see if I'm running from JAR? Hi all,

is it possible for a Java application identify if it is running
from a Jar file?
Any functions?

thanks
giammy

 
giangiammy@gmail.com





PostPosted: 2006-7-4 23:30:00 Top

java-programmer >> How can I see if I'm running from JAR? Found an example:
thanks
giammy

public class HelloClass {
public static void main(String[] args) {
new HelloClass().say();
}


public void say() {
String className = this.getClass().getName().replace('.', '/');
String classJar = this.getClass().getResource("/" + className +
".class").toString();
if (classJar.startsWith("jar:")) {
System.out.println("*** running from jar!");
}
System.out.println(classJar);

}
}

 
Alan Krueger





PostPosted: 2006-7-5 0:49:00 Top

java-programmer >> How can I see if I'm running from JAR? email***@***.com wrote:
> is it possible for a Java application identify if it is running
> from a Jar file?
> Any functions?

boolean isRunningInJar() {
return getClass().getProtectionDomain().getCodeSource()
.getLocation().getPath().endsWith( ".jar" );
}