6.16.2013

I think many people (who is interested in the J2EE developing) faced the situation when after deploying and running the project you see something like this in the address bar:
http://localhost:8080/Yourproject-war/
This article will be useful for those who want to rid of the root context and port defining in the address bar. So in the end of the article you will achieve this:
http://localhost
Let's start from the simplest part - removing root context from the address bar.  In order to not show "Yourproject-war" part you can simply just open the Glassfish Admin Console (http://localhost:4848), go to the Configurations -> default-config -> Virtual Servers -> server section and set your project as the Default Web Module. That is all. Now you can access your deployed project using this link:
http://localhost:8080
Now I will describe more difficult part - how to use 80 port instead of 8080 for Glassfish. As you may know, non-root users can not use ports from the range < 1024. In order to assign 80 port for Glassfish you can use two options: install a glassfish as a root or use workaround that I will describe.

Let's begin.

I soppose that Glassfish server is already installed on your system. If not - please install it (you just need to download and unzip the archive).

In order to use 80 port we will use an utility called "authbind". Authbind lets you bind ports without beeing root. So we need to install authbind first and create a dummy file, to grant access to the user you would like to.
// first install authbind
sudo apt-get install authbind
// now create a dummy file which tells autbind who can access port 80
touch /etc/authbind/byport/80
chmod 500 /etc/authbind/byport/80
// change glassfish to your personal glassfish user or user that you are using every day :)
chown your_user /etc/authbind/byport/80
For me, for example, the command was look like this:
chown deezzel /etc/authbind/byport/80
Now you need to create the /etc/init.d/glassfish file and put the following content into it:

#! /bin/sh

#path to the glassfish directory
GLASSFISHPATH=/home/glassfish/glassfish/bin
case "$1" in
start)
echo "starting glassfish from $GLASSFISHPATH"
#domain1 - this is your configured domain for glassfish
sudo -u your_user authbind --deep $GLASSFISHPATH/asadmin start-domain domain1
;;
restart)
$0 stop
$0 start
;;
stop)
echo "stopping glassfish from $GLASSFISHPATH"
sudo -u your_user authbind --deep $GLASSFISHPATH/asadmin stop-domain domain1
;;
*)
echo quot;usage: $0 {start|stop|restart}"
exit 3
;;
esac

At this step you are done.

Now you can start|stop|restart glassfish from the /etc/init.d/ directory as the service. Moreover, now
Glassfish is listen port 80 and you are able to access your deployed project via the link:
http://localhost
Now you can buy a domain name and use it for your project to access it through the WWW.

Please feel free to ask any questions or let me know if you find a mistake. Thanks. 

0 коммент.:

Subscribe to RSS Feed Follow me on Twitter!