Monthly Archives: June 2013

Access private fields per Reflections within Glassfish

You can not access a private field per Reflections, if your application runs on Glassfish. You have to set a policy entry on the server to permit it:

1. open the security policy file: glassfishv3/glassfish/domains/domain1/config/server.policy
2. include the following entry:

        grant codeBase "file:${com.sun.aas.installRoot}/domains/domain1/applications/arena-dwr/-" {
            permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
        };

Don’t forget to replace the arena-dwr by the name of your application, and also to check project path if you are not using the default container instance domain1.

Then you can call:

   Entity.class.getDeclaredFields()

without a SecurityException.