How to do it...

Follow these steps:

  1. First, we are deploying EAR, WAR, and JAR files. For EAR and WAR files, the deployment folder is the following:
 $GLASSFISH_HOME/glassfish/domains/[domain_name]/autodeploy

Usually domain_name is domain1, unless you've changed it in the installation process. For JAR files, the folder is $GLASSFISH_HOME/glassfish/lib.

  1. To create a datasource and a connection pool to help you use databases in your project, edit the $GLASSFISH_HOME/glassfish/domains/[domain_name]/config/domain.xml file. Inside the <resources> node, insert a child node like this one:
<jdbc-connection-pool 
pool-resize-quantity="4"
max-pool-size="64"
max-wait-time-in-millis="120000"
driver-classname="com.mysql.jdbc.Driver"
datasource-classname="com.mysql.jdbc.jdbc2.optional
.MysqlDataSource"
steady-pool-size="16"
name="MysqlPool"
idle-timeout-in-seconds="600"
res-type="javax.sql.DataSource">
<property name="databaseName" value="database"></property>
<property name="serverName" value="[host]"></property>
<property name="user" value="user"></property>
<property name="password" value="password"></property>
<property name="portNumber" value="3306"></property>
</jdbc-connection-pool>
<jdbc-resource pool-name="MySqlDs" jndi-name="jdbc/MySqlDs">
</jdbc-resource>
  1. Then, look for this node:
<server config-ref="server-config" name="server">
  1. Add this child to it:
<resource-ref ref="jdbc/MySqlDs"></resource-ref>

The example targets MySQL, so you will need to make some changes if you are using another database. Of course, you will also need to change the other parameters according to your needs.

  1. To configure logging for Eclipse GlassFish, edit the $GLASSFISH_HOME/glassfish/domains/domain1/config/logging.properties file. The file works with handlers like this:
handlers=java.util.logging.ConsoleHandler
handlerServices=com.sun.enterprise.server.logging.GFFileHandler
java.util.logging.ConsoleHandler.formatter=com.sun.enterprise.server.logging.UniformLogFormatter
com.sun.enterprise.server.logging.GFFileHandler.formatter=com.sun.enterprise.server.logging.ODLLogFormatter
com.sun.enterprise.server.logging.GFFileHandler.file=${com.sun.aas.instanceRoot}/logs/server.log
com.sun.enterprise.server.logging.GFFileHandler.rotationTimelimitInMinutes=0
com.sun.enterprise.server.logging.GFFileHandler.flushFrequency=1
java.util.logging.FileHandler.limit=50000
com.sun.enterprise.server.logging.GFFileHandler.logtoConsole=false
com.sun.enterprise.server.logging.GFFileHandler.rotationLimitInBytes=2000000
com.sun.enterprise.server.logging.GFFileHandler.excludeFields=
com.sun.enterprise.server.logging.GFFileHandler.multiLineMode=true
com.sun.enterprise.server.logging.SyslogHandler.useSystemLogging=false
java.util.logging.FileHandler.count=1
com.sun.enterprise.server.logging.GFFileHandler.retainErrorsStasticsForHours=0
log4j.logger.org.hibernate.validator.util.Version=warn
com.sun.enterprise.server.logging.GFFileHandler.maxHistoryFiles=0
com.sun.enterprise.server.logging.GFFileHandler.rotationOnDateChange=false
java.util.logging.FileHandler.pattern=%h/java%u.log
java.util.logging.FileHandler.formatter=java.util.logging.XMLFormatter

So, you can define the logging level, directory, format, and more according to your needs.

  1. If you need to configure log rotation, you have to focus on these lines:
com.sun.enterprise.server.logging.GFFileHandler
.rotationTimelimitInMinutes=0
com.sun.enterprise.server.logging.GFFileHandler
.rotationLimitInBytes=2000000
com.sun.enterprise.server.logging.GFFileHandler
.maxHistoryFiles=0
com.sun.enterprise.server.logging.GFFileHandler
.rotationOnDateChange=false

In this example, we are defining this file to rotate on every 2,000 kilobytes (2 MB) and will not rotate on date change. There's no limit for history files.

  1. To start Eclipse GlassFish, just execute this script: 
$GLASSFISH_HOME/bin/asadmin start-domain --verbose
  1. To stop it, execute the following script:
 $GLASSFISH_HOME/bin/asadmin stop-domain
  1. Building a cluster using GlassFish is a little tricky and involves using both the command line and the admin panel, but it is completely doable! Let's check it out:
    1. First, you need two or more instances (called nodes) up and running. You can do it in any way you like—each one running in a different machine, using virtual machines, or using containers (my favorite option). Whichever way you choose, the way of getting the cluster up is the same.
    2. Get your first node and open its admin panel at https://[hostname]:4848.
    3. Click on the Clusters option in the left menu and then click on the New button. Name the cluster myCluster and click on the OK button.
    4. Select your cluster from the list. On the opened page, select the Instances option in the tab and then click on New. Name the instance node1 and click on OK.
    5. Now, go to the General tab and click on the Start Cluster button. Voilá! Your cluster is up and running with your first node.
    6. Now, go to the second machine (VM, container, other servers, or any server) with GlassFish already installed and run this command:
$GLASSFISH_HOME/bin/asadmin --host [hostname_node1] --port 4848 create-local-instance --cluster myCluster node2

This will set the second machine as a member of the cluster. If you refresh the Cluster page on the first machine, you will see the new member (node2).

    1. You will notice that node2 has stopped. Click on it and on the new page, click on the Node link (it will usually show the hostname of node2).
      1. On the opened page, change the Type value to SSH. Some new fields will show up in an SSH section.
      2. Change SSH User Authentication to SSH Password and fill the SSH User Password field with the right password.
      3. Click on the Save button. If you encounter an SSH error (usually connection refused), set the Force option to Enabled, and click on Save button again.
      4. Go back to the command line on the machine hosting node2 and run this command:
    $GLASSFISH_HOME/glassfish/lib/nadmin start-local-instance --node [node2_hostname] --sync normal node2

    If everything went well, your node2 should be up and running and you should now have a real cluster. You can repeat these steps however many times you need to add new nodes to your cluster.

    ..................Content has been hidden....................

    You can't read the all page of ebook, please click here login for view all page.
    Reset