tags:

views:

334

answers:

5

I'm using the BrowserLauncher2 library for opening the user's default web browser from my Swing app, but it's throwing a very confusing exception:

public static void openURL(String url) {
        try{
            BrowserLauncher launcher = new BrowserLauncher();
            launcher.openURLinBrowser(url);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

Exception:

edu.stanford.ejalbert.exception.BrowserLaunchingExecutionException: java.lang.reflect.InvocationTargetException
    at edu.stanford.ejalbert.launching.macos.MacOs3_1BrowserLaunching.openUrl(MacOs3_1BrowserLaunching.java:61)
    at edu.stanford.ejalbert.BrowserLauncherRunner.run(BrowserLauncherRunner.java:136)
    at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at edu.stanford.ejalbert.launching.macos.MacOs3_1BrowserLaunching.openUrl(MacOs3_1BrowserLaunching.java:58)
    ... 2 more
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission canOpenURLs)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
    at java.security.AccessController.checkPermission(AccessController.java:427)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at com.apple.eio.FileManager.openURL(FileManager.java:229)
    at com.apple.mrj.MRJPriv.openURL(MRJPriv.java:255)
    at com.apple.mrj.MRJFileUtils.openURL(MRJFileUtils.java:206)
    ... 7 more
+1  A: 

You are running your application with a SecurityManager set. Some code in the AccessControlContext (a.k.a. acc) does not have the required permission. Probably that code is your application code.

Tom Hawtin - tackline
+1  A: 

An InvocationTargetException always wraps another exception which was caused while invoking a method or constructor via reflection. To solve your problem, you need to look at the exception under it, the IllegalAccessException which as Tom Hawtin points out, is being thrown because of the SecurityManager.

Steve Reed
A: 

i'm trying to istall a programm and i have the same problem.what should i do?

A: 
JRL
A: 

I was getting AccessControlExceptions with BrowserLauncher2 via an applet of mine. Your situation may be similar, because you are running your app with a SecurityManager.

I solved my problem by signing the BrowserLauncher2 jar with my certificate. If your user accepts your certificate, BrowserLauncher should have the permissions it needs to do its job.

Stephen Harmon