.:An Endless Journey:.
open source and me
  • Immutable Page
  • Info
  • Attachments

Notes on Glassfish (and SJSAS)

Unanwsered Questions

  1. How to set property -Dxxx=yyy to deployed modules? Set it in asadmin.bat or domain.xml (jvm-options) doesn't have any effect
  2. How to disable the auto. loading of JPA in Glassfish (I use Spring managed local container)

Where to put log4j.xml in EAR

Quick Answer::

  • Put it in one of the ejb-jar. Make sure no other log4j config presents in any jar within the EAR.

Long Answer:

  • Basically, it is a matter of classloader issue. When deploying EAR, the whole EAR is bound to one application classloader. (See Glassfish developer guide for details)

How to solve the Jar locking issue (Windows platform)

See this thread for details:

Quick workaround:

  • Use Glassfish v2 (I haven't verified it yet)
  • Use deploydir instead of deploy (when redeploy, glassfish will not 'delete' jar, hence the problem is avoided)

Create MySQL connection pool

  1. Put mysql jdbc jar in domains/domain1/lib/
  2. In the admin console, create connection poll:

  <Step 1>
  Name:             127.0.0.1/Hello
  Resource Type:    javax.sql.ConnectionPoolDataSource
  Database Vendor:  mysql

  <Step 2>
  Datasource class: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
  Resource Type:    javax.sql.ConnectionPoolDataSource

  Allow Non-component callers: YES

  Properties
    databaseName:    Hello
    serverName:      127.0.0.1
    port:            3306
    user:            db_username
    password:        db_password
  1. Create JNDI ref.

  JNDI :    jdbc/Hello
  Pool :    127.0.0.1/Hello

Two types of Password in Glassfish

Master Password::

  • Each domain have a keystore: domains/[domain]/config/keystore.jks The keystore hold SSL certs for HTTPS services in the domain Masster password is used to protect this keystore

Admin Password::

  • User can administrate SJSAS through asadmin or Admin Console interface. When create a domain, you should specify the admin account for these services. The password for the administrator account is 'adminpassword'

During domain creation, you can ask it save both types of password in local filesystem. If you do so, you do not have to provide any password when you execute asadmin to configure resources / deploy applications on the domain.

  $ asadmin create-domain --savemasterpassword=true --savelogin=true new_domain_name

The Admin password is saved in:

  $HOME/.asadminpass

Create domain using alternative port

  $ asadmin create-domain --domaindir /path/to/glassfish/domains.staging \
                        --adminuser admin \
                        --adminport 34848 \
                        --instanceport 38080 \
                        --domainproperties jms.port=37676:domain.jmxPort=30001:orb.listener.port=30002:orb.ssl.port=30003:orb.mutualauth.port=30004:http.ssl.port=38443 \
                        --savemasterpassword=true \
                        --savelogin=true \
                        staging

Note, you need to specify the 'domain dir' for start / stop domain

  $ asadmin start-domain --domaindir [path/to/new_domain_dir]
  $ asadmin stop-domain --domaindir [path/to/new_domain_dir]

Note, you need to specify the 'admin port' on any asadmin command, eg:

  $ asadmin list-components --port 34848
  $ asadmin add-resources --port 34848
  $ asadmin undeploy --port 34848

Multiple installation of Glassfish

Install them on diff. directory. For each $INSTALL_DIR/bin, add the path to $PATH In each $INSTALL_DIR/bin copy the asadmin.bat => diff name like gfadmin-v2.bat

Then, use this

  • gfadmin-v2.bat start-domain gfadmin-v2.bat list-components

Make sure each install have a same admin password. asadmin will always try to find password from $HOME/.asadminpass The file contains 'one' password for 'username@hostname' config.

After all, The simplest way is to make sure that, all installation have same admin password.

If the current password does not align, you can change password for one-by-one with:

  # Start the installation
  $ asadmin login --user admin
  $ asadmin change-admin-password --user admin
  # Stop the installation

Forgetting Admin Password

Create a new domain by asadmin create-domain --savelogin=true Copy the domains/[new-domain-name]/config/admin-keyfile To the domains/[old-domain-name]/config/admin-keyfile asadmin delete-domain xyz