tweety this is probably too late for you but I was having the same problem with GlassFish 4 and JDK1.7.0_21. I thought I would post in case it is useful for someone else.
Looking at the findDerbyClient in CommonClassLoaderServiceImpl, it can locate Derby home in a couple of different ways, from the StartupContext or relative to the java.home System Property.
I was running in eclipse which by default runs apps using the JRE. DERBY can’t be found relative to the JRE's java.home. Switching to running under the JDK fixed this as it could find DERBY relative to the JDK’s java.home.
Before I realised this I traced it through and came up with a convoluted way of initializing the StartupContext for standalone clients. I certainly wouldn’t use this hack in production but it might be useful for other test scenarios.
Add the following imports:
Add the following code before you create the ProgrammaticLogin:
Properties properties = new Properties();
properties.setProperty("AS_DERBY_INSTALL", "C:/glassfish4/javadb"); // assuming default location
ModulesRegistry modulesRegistry = new StaticModulesRegistry(Globals.class.getClassLoader(), new StartupContext(properties));
This might have some unforeseen side effects so use with caution.