I've been working with / struggling with Glassfish a lot lately. The documentation leaves much to be desired, so there are a few bits and pieces you might not know that might come in handy.
These notes refer to Glassfish 3.1.
asadmin list-commands to list supported commands, and
asadmin help commandname for details. Read all of
asadmin help since it contains important info the subcommand references should mention, but don't.
asadmin list * to list all Glassfish properties. This is important when working on embedded, because most configuration can only be done using
asadmin set. In embedded glassfish you can run this on your embedded instance using:
commandRunner = glassfish.getService(CommandRunner.class); CommandResult result = commandRunner.run("list","*"); System.err.println("Got command result: " + result.getOutput());
set commands to manipulate the objects you discover with
Creating users in a file realm
Creation of users non-interactively - for batch/script use - is possible using the
asadmin create-file-user command. It's not possible to pass a user password to the command directly because it rejects the --AS_ADMIN_USERPASSWORD argument with "passwords not allowed on command line". You must create an asadmin password file that contains the new user password to set as well as the admin password required to use the admin command. See
asadmin help for details on the password file's weirdness and on the
help create-file-user doesn't mention it at all.
maven-embedded-glassfish-plugin is very limited. It doesn't offer facilities to deploy a
asadmin commands pre/post deploy, etc. If you're using container provided resources, avoid it and run an embedded Glassfish instance directly in your application or tests instead. The Glassfish embedded API (see below) is pretty easy to use and unlike the Maven plugin gives you the flexibility to invoke
asadmin commands to set up your domain to fit your needs.
There are references to a different maven plugin with a slightly different name out there. It's not the same thing, doesn't exist in Glassfish 3, and won't do what you want.
Documentation for the embedded glassfish 3.1 api
The Glassfish 3.1 embedded documentation is here: http://embedded-glassfish.java.net/nonav/apidocs/org/glassfish/embeddable/GlassFish.html. Most of the documentation has been removed from the Oracle Glassfish Embedded guide. The API has changed significantly from 3.0, so the 3.0 guide is just misleading.
asadmin from embedded
If you run your own standalone embedded glassfish, you can invoke
asadmin commands using the CommandRunner. However, a frustrating bug caused by a feature removed without considering the impact on embedded means you can't create file users for a file realm this way. See http://java.net/jira/browse/GLASSFISH-16277. I don't have a solution for this issue yet.
Glassfish has a REST driven admin interface in addition to
asadmin and the web console. This can be a powerful facility for automation, but is almost totally undocumented. Exploring it using `curl' can be informative, because it's based on JAX-RS so paths can report the supported subpaths, etc.