How to Run Asadmin Commands in Embedded GlassFish
You can leverage your experience and knowledge about the GlassFish command line tool, asadmin, with Embedded GlassFish servers.
Here is a use case:
You want an Embedded GlassFish server that uses a JavaDB database. You need to setup a few things in the server configuration. You can do this configuration in your code every time you start using the CommandExecutor. Another possibility is to do the following:
- start the Embedded GlassFish server -- making sure autodelete is off
- Run asadmin commands for configurationmbedded GlassFish server
- Stop the Embedded GlassFish server
- Always set the install-root to the root of the generated file system from steps 1,2.
Here is how to run asadmin in Embedded GlassFish (embedded.jar is the Embedded GlassFish all-in-one jar file that you have downloaded or built)
Windows:
java -cp final.jar com.sun.enterprise.admin.cli.AsadminMain %*
*NIX:
java -cp final.jar com.sun.enterprise.admin.cli.AsadminMain $*
I wonder whether I can use this to write unit tests for EJBs..
Posted by blah on July 14, 2009 at 03:32 AM PDT #
For EJB testing, GlassFish v3 implements the now standard EJBContainer.createEJBContainer() API. You'll need to have glassfish/lib/embedded/glassfish-embedded-static-shell.jar in your classpath (or a bunch of maven dependencies). See http://blogs.sun.com/kensaks/entry/embeddable_ejb for an intro.
Posted by Alexis MP on September 23, 2009 at 11:51 PM PDT #