How to Install GlassFish on CentOS RedHat Fedora

How to Install GlassFish ESB on CentOS / Red Hat / Fedora

I did my installation on a CentOS 5.4 and I confirm all works, just follow

Download JDK 6u12
# cd /usr
# wget

Download GlassFish 2.1
# wget

Check current Java Version
# java -version
java version “1.6.0″
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK Server VM (build 1.6.0-b09, mixed mode)
# chmod +x /usr/jdk*
# ./usr/jdk-6u12-linux-i586.bin
Accept License, and enter

Adjust path
#vim /etc/profile

You may need to logout and login then:
# java -version
java version “1.6.0_12″
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Server VM (build 11.2-b01, mixed mode)

Create user
# adduser esb
# passwd esb
# mkdir /usr/local/GlassFishESBv21
# mkdir /home/esb
# chown esb:root -R /usr/local/GlassFishESBv21
# mv /usr/ /home/esb
# chown esb:root -R /home/esb/GlassFishESBv21
# chmod 755 -R /home/esb/GlassFishESBv21

Add it to sudoers just for now
# vim /etc/sudoers



Login into the Gnome interface localy (via VNC wont work)
with the esb user execute from /home/esb
# sudo bash

On the install GUI
Set NetBeans IDE to:
Set Install GlassFish to:

Now lets configure the service to autostart
# cd /etc/rc.d/init.d
# vim glassfish

#Script to start/stop/restart GlassFish
# chkconfig: 35 20 80
# description: GlassFish ESB 2.1 Daemon
case “$1″ in
${GFPATH}/asadmin start-database
${GFPATH}/asadmin start-domain domain1
${GFPATH}/asadmin stop-database
${GFPATH}/asadmin stop-domain domain1
${GFPATH}/asadmin stop-domain domain1
${GFPATH}/asadmin start-domain domain1
echo $”Usage: $0 {start|stop|restart}”
exit 1

# chkconfig –add glassfish
# chkconfig –level 35 glassfish on
# service glassfish start

Once the service start it Should Display:

Starting database in the background.
Log redirected to /usr/local/GlassFishESBv21/glassfish/databases/derby.log.
Command start-database executed successfully.
Starting Domain domain1, please wait.
Default Log location is /usr/local/GlassFishESBv21/glassfish/domains/domain1/logs/server.log.
Redirecting output to /usr/local/GlassFishESBv21/glassfish/domains/domain1/logs/server.log
Domain domain1 is ready to receive client requests. Additional services are being started in background.
Domain [domain1] is running [Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)] with its configuration and logs at: [/usr/local/GlassFishESBv21/glassfish/domains].
Admin Console is available at [http://localhost:4848].
Use the same port [4848] for “asadmin” commands.
User web applications are available at these URLs:
[http://localhost:8080 https://localhost:8181 ].
Following web-contexts are available:
[/web1 /__wstx-services ].
Standard JMX Clients (like JConsole) can connect to JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://SERVERESB:8686/jmxrmi] for domain management purposes.
Domain listens on at least following ports for connections:
[8080 8181 4848 3100 3820 3920 8686 ].
Domain does not support application server clusters and otherstandalone instances.

To login via web go to


Remeber to open firewall for ports required
Check with ps if service is running
Reference to official documentation at:

Good Simple example with Glassfish and a RESTful webservice Using JMS

In this little tutorial, we will create a simple MessageDriven bean. It will consume messages which are produced in a simple way by a RESTful webservice, We will also make use of Glassfish server and JMS. Let go!!


Setup Glassfish

You need a clean installation of Glassfish (v2 or v3). I also recommend an IDE with Glassfish integration. Netbeans should be easiest as I’ve heard that it’s got the best Glassfish integration, but I am using Eclipse 3.5. I won’t cover the setup process in your IDE – if you’re having difficulties, please let me know.

The few basic steps you need to do is:

  1. Install Glassfish (e.g. /dev/glassfishv3/)
  2. Setup Glassfish in Eclipse via Window->Preferences->Server->Runtime Environments and point it to /dev/glassfishv3/glassfish. The result should look like this:
  3. Add the “Server” view if it doesn’t show up yet and add a new Server (RMB->New->Server):serverconfig2
    You should get a server entry and be able to start and stop the instance.

    Please verify if that works, first. Now you can start up Glassfish.

Configure Glassfish

Open a command prompt or terminal in /dev/glassfishv3/bin/ and be sure that Glassfish is running. Then create the JMS queues in glassfish (works with v2 and v3) with the asadmin tool:

asadmin create-jms-resource –restype javax.jms.ConnectionFactory jms/SimpleConnectionFactory
asadmin create-jms-resource –restype javax.jms.Queue jms/SimpleQueue

The implementation

Now we need some code. We will use a MessageDriven bean to consume the messages and a RESTful webservice to produce them in a simple way. For the MessageDriven bean, create a “EJB project” (Eclipse: New -> Project -> EJB/EJB Project) and put the following class in there:

import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

* Simle message driven bean.
@MessageDriven(mappedName = “jms/SimpleQueue”)
public class SimpleMessageDrivenBean implements MessageListener {

* Default constructor.
public SimpleMessageDrivenBean() {
* @see MessageListener#onMessage(Message)
public void onMessage(Message message) {
try {
System.out.println(“Got message: ” + ((TextMessage)message).getText() + ” @” + System.currentTimeMillis());
} catch (JMSException e) {


Now we need a Web Project which contains the RESTful Webservice (Eclipse: New -> Project -> Web/Dynamic Web Project). Add the following class to that project:


import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.NamingException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;

* Example of a RESTful webservice producing messages for a JMS Queue.
* Call via http://localhost:8080/webservicetest/jms
* @author Matthias Fraass
@Stateless // dependency injection won’t work without that
@Path(“/jms”) // path appended to context root -> http://localhost:8080/webservicetest/jms
public class SimpleJMSRestfulWebService {

@Resource(mappedName = “jms/SimpleConnectionFactory”) //= connection factorie’s JNDI name
private ConnectionFactory connectionFactory;

@Resource(mappedName = “jms/SimpleQueue”) //= Queue’s JNDI name
private Queue queue;

* Our RESTful webservice
public String putMessage() throws NamingException, JMSException, NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
System.out.println(“called putMessage”);
javax.jms.Connection  connection = connectionFactory.createConnection();
javax.jms.Session        session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
long start = System.currentTimeMillis();
int i=0;
TextMessage message = session.createTextMessage();
message.setText(“Hello, JMS! #”+start);
while (i < 1000);
long now = System.currentTimeMillis();
return “JMS produced 1000 messages within ” + (now-start) + “ms”;


Now you need to configure the Jersey Servlet in web.xml, so that it picks up the WebService. Put the following in betwen the display-name and the welcome-file-list tags.


<servlet-name>Jersey Web Application</servlet-name>











<servlet-name>Jersey Web Application</servlet-name>




This WebService will produce 1000 messages and output the time it took. We’ll use that to compare the performance of different distribution scenarios and message queue products during the course of the next articles.


The last thing we need is the EAR project (New -> Project / JavaEE/Enterprise Application Project). Add the EJB and the Web project to the EAR project. The result will be:


You should now be able to deploy that in glassfish:


and then


The server.log (glassfish/domains/domain1/logs/server.log or in the Eclipse Console – be sure to switch to “server.log”) should output this:

INFO: DOL Loading time150INFO: endpoint.determine.destinationtype

INFO: Portable JNDI names for EJB SimpleJMSRestfulWebService : [java:global/JMS1/JMS1web/SimpleJMSRestfulWebService, java:global/JMS1/JMS1web/SimpleJMSRestfulWebService!]
INFO: Unknown loader org.glassfish.internal.api.DelegatingClassLoader@11b92ef class org.glassfish.internal.api.DelegatingClassLoader
INFO: Scanning for root resource and provider classes in the packages:
INFO: Root resource classes found:
INFO: Provider classes found:
INFO: Initiating Jersey application, version ‘Jersey: 1.1.0-ea 04/30/2009 06:59 PM’
INFO: Binding the EJB class to EJBManagedComponentProvider
INFO: Loading application JMS1#/C:/dev/glassfishv3/glassfish/domains/domain1/eclipseApps/JMS1/JMS1web_war/ at JMS1web
INFO: Deployment of JMS1 done is 992 ms

Then, point a browser to e.g. http://localhost:8080/JMS1web/jms/ and you should see “JMS produced 1000 messages within XYms” in your browser (doesn’t work with Chrome) The server.log should look like this:

INFO: called putMessage ..
INFO: Got message: Hello, JMS! #1257518116879 @1257518117079
INFO: Got message: Hello, JMS! #1257518116879 @1257518117089 …

Vóila! Your first JMS enterprise project is running! It is using the internal OpenMQ instance of Glassfish, which is running on port 7676 by default. That’s not *remote* messaging yet, but it can already enable you to asynchronously process tasks. That’s good for most smaller projects or local development and testing We will use that simple example as a starting point for the following, more demanding ;) tutorials which will do remote messaging.

Original Post :

Sun Publishes Glassfish vs. JBoss Comparison Guide

Poor Redhat.  First SpringSource declares war and now Sun is joining in.  Today Sun made available a 14 page Glassfish vs. JBoss Comparison Guide, (Sun login required to download).  Check it out.  It actually makes for pretty interesting reading and if I was eager to see Redhat/JBoss’s response to SpringSource, they’ve now got me besides myself with excitement waiting to hear how they respond to both SpringSource and Sun!  It’s going to be epic!!

Or if you are not a Sun USER, you can download the PDF from here Glassfish vs Jboss.PDF

How to change Glassfish server default ports

Very simple steps

  1. Open (in notepad or other text editor) domain.xml located in /glassfish/domains/domain1/config folder.
  2. Search for 8080 (there should be one occurance only ideally)
  3. Change it to 80 or 8088 or 8090 – whatever port no. you like and start the server.
  4. There is no step 4 🙂

All your calls to glassfish server now do not require 8080 in your url. This should work same on other platforms as well though I have not tested it. This way you should be able to change glassfish server other ports as well.