AppBundler: wrong working directory
Steve Hannah
steve at weblite.ca
Sat Sep 15 13:04:05 PDT 2012
Sorry to revive an old thread, but I'm having some trouble on this exact
issue, and the CWD approach doesn't seem to work on Lion.
A solution that works (for setting the CWD) on Mountain Lion (with or
without Sandboxing) is:
1. In the appbundler ANT task
<option value="-Duser.dir=Contents/Resources"/>
2. In the Application's main() method:
System.setProperty("user.dir", new File(".").getCanonicalPath());
The 2nd part is necessary to avoid the following errors whenever you try to
access the file system in any way:
java.lang.RuntimeException: default directory must be absolute
However, on Lion (with Sandboxing) this fails to work. Even with #2
System.setProperty("user.dir", new File(".").getCanonicalPath());
I end up with the error:
java.lang.RuntimeException: default directory must be absolute
whenever I try to access the file system in any way.
E.g.
System.setProperty("user.dir", new File(".").getCanonicalPath());
System.out.println(new File(".").toURI());
System.out.println("Working directory: "+(new
File(".").getCanonicalPath()));
Will output:
file:/Contents/Resources/.
Working directory: Contents/Resources
On Lion.
Haven't tested it on Snow Leopard.
On Mountain lion the output looks like:
file:/absolute/path/to/MyApp.app/Contents/Resources/.
Working directory: /absolute/path/to/MyApp.app/Contents/Resources
Which is correct.
This is using the 1.7.0u.jdk binary from 20120912 at
http://code.google.com/p/openjdk-osx-build/downloads/detail?name=OpenJDK-OSX-1.7-universal-u-jdk-u10-b06-20120912.dmg
And either the Oracle Appbundler or Marco's fork of it.
Ideally we could have a macro in the app bundler that always resolves to
the Application bundle root like we had in the old jarbundler ANT task.
Does anyone know of a workaround to this?
Best regards
Steve
On Wed, Feb 29, 2012 at 5:56 PM, Mike Swingler <swingler at apple.com> wrote:
> On Feb 29, 2012, at 7:56 AM, Greg Brown wrote:
>
> >>> <option value="-Duser.dir=Contents/Resources"/>
> >>
> >> That is less onerous for developers to adopt, but it's quite a subtle
> thing which is not self-documenting.
> >
> > Perhaps, but macro expansion isn't really self-documenting either.
>
> Well, the name of the macro should explain what it expands to. If it
> doesn't, it has a bad name.
>
> > I actually had no idea until I looked at the source code for the earlier
> launcher that it was even supported. Plus, it's pretty easy to document
> that the default working directory for a bundled app is the bundle root. As
> a developer, you might even assume this.
>
> How could the developer assume where the root is? The .app bundle, the
> Contents/ directory, or the Contents/Java directory?
>
> >> I'd still advocate for macro expansion (and I'd be happy to provide a
> diff) if that's a direction you'd support as well.
> >
> > I'd prefer to stick with the idea of setting the default working
> directory to the bundle root for now. It seems like it would address all of
> the issues that have come up so far and is less complex than adding macro
> support.
>
> That's reasonable. I'm sure if setting the CWD alone is insufficient,
> someone will speak up. :-)
>
> Regards,
> Mike Swingler
> Apple Inc.
>
>
--
Steve Hannah
Web Lite Solutions Corp.
More information about the macosx-port-dev
mailing list