Thursday Feb 05, 2009

Use CommandExecutor to run asadmin commands in Embedded GlassFish

CommandExecutor is a general API to programmatically run asadmin commands in Embedded GlassFish.
See javadocs. I'll show how you can use it.

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);
server.start();
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();
options.setProperty("DEFAULT", "HTTP_LISTENER_PORT=38080:HTTP_SSL_LISTENER_PORT=38181");
ce.execute("create-system-properties", options);

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

becomes

options.setProperty("datasourceclassname", "myDataSourceClass");
options.setProperty("DEFAULT", "myConnPool");
ce.execute("create-jdbc-connection-pool", options);

Use options.clear() between different command executions.

You can also deploy a war.

asadmin deploy c:\\samples\\hello.war

becomes

options.setProperty("DEFAULT", "c:\\\\samples\\\\hello.war");
ce.execute("deploy", options);

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.

Friday Feb 01, 2008

Glassfish V3 - Getting Started, Setting up the Environment

Sreeni gave me instructions on how to get started and setup with Glassfish V3. It worked like a charm so I thought I would post it here. Thanks Sreeni!

1. Download and install Java SE 6.latest:
http://java.sun.com/javase/downloads/index.jsp
• Set the system/user variable JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_04
• Add %JAVA_HOME%\\bin to your system path.

2. Download and install SVN:
http://downloads.open.collab.net/collabnet-subversion.html
http://wiki.glassfish.java.net/attach/V3BrownBags/GFV3Intro2svn.pdf
• Add the svn directory to your system path.

3. Download and install Maven2:
http://maven.apache.org/download.html
• Add the system/user variable M2_HOME
• Add $M2_HOME/bin directory to your system path.
• Type the following:
mvn –version
You should see: Maven version: 2.0.8
http://wiki.glassfish.java.net/attach/V3BrownBags/GFv3Intro2Maven2.pdf

4. Checkout code:
svn checkout https://svn.dev.java.net/svn/glassfish-svn/trunk/v3

5. Build:
cd ${GFSRCDIR}/v3
mvn -U install

6. Install app server:
Expand glassfish.zip $GFv3\\v3\\distributions\\glassfish\\target\\glassfish.zip

7. Start app server
cd /glassfish/bin
./asadmin start-domain

For additional info.
http://wiki.glassfish.java.net/Wiki.jsp?page=V3FullBuildInstructions

About

Jennifer Chou

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today