Sunday, April 12, 2009

User home dirs ("user.dir") on the Google App Engine/J

A Java application running on the Google App Engine is only allowed to read files stored inside the user's home dir. The path to this directory is stored in the read-only system property "user.dir" (System.getProperties().get("user.dir")).

Trying to read files outside of your home dir will raise the following exception:
java.security.AccessControlException: access denied (java.io.FilePermission ... read)
The path of the "user.dir" on Google App Engine/J follows the following structure:
/base/data/home/apps/[app-id]/[version-id]
The version-id appears to be a version identifier followed by a dot (".") and then an 18 digit random number.

A new home directory is created each time you deploy your app using "appcfg.sh update".

Combining the fact that you're allowed to read your own home dir with the fact that a new deployment gives rise to a new home dir gives you the following method to get the exact date and time of your last deployment:
Date deployTime = new Date(new File((String) System.getProperties().get("user.dir")).lastModified());

1 comments:

morsi_j said...

Hello,
Is that mean that the only solution to save textual data is the JDO Or JPA of google app engine??

Post a Comment