Use CommandExecutor to run asadmin commands in Embedded GlassFish
By Jennifer Chou on Feb 05, 2009
You will need the glassfish-embedded-all-v3-prelude-\*.jar. You can download the latest nightly build and use latest.jar.
Before you use CommandExecutor, you must first start Server:
EmbeddedInfo ei = new EmbeddedInfo();
Server server = new Server(ei);
CommandExecutor ce = server.getCommandExecutor();
Look-up a command you want to try from the Administration Commands section of the Sun GlassFish Enterprise Server v3 Prelude Reference Manual
Let's try create-system-properties.
The command name is create-system-properties.
The default operand is one or more name-value pairs.
If you are familiar with asadmin commands, it would like this if you were running from the asadmin command line.
asadmin create-system-properties HTTP_LISTENER_PORT=38080:HTTP_SSL_LISTENER_PORT=38181
Using the CommandExecutor, the above would translate to
Properties options = new Properties();
Always use "DEFAULT" as the property name of the default operand. In addition to the default operand, other commands may have additional required options. For example, create-jdbc-connection-pool has datasourceclassname as a required option and connectionpoolid as the default operand.
asadmin create-jdbc-connection-pool --datasourceclassname myDataSourceClass myConnPool
options.clear() between different command executions.
You can also deploy a war.
asadmin deploy c:\\samples\\hello.war
Run your test class that deploys your war. The default port is 8888.
java -cp latest.jar;TestCommandExecutor.jar testcommandexecutor.Main
Check your web application. http://localhost:8888/hello/
I haven't tested all the commands that are supported in GlassFish v3 Prelude, but most should work. I do know that start-database and stop-database will not work because Embedded GlassFish does not bundle JavaDB.