Wednesday, December 19, 2007

How to install GlashFish Server on linux?

Installing GlassFish Server on Linux

1)    Install JDK on a system and set JAVA_HOME environmental variable.

       If you don't have GlassFish server, U can download GlassFish Server from following location.

2)    Run:

       java -Xmx256m -jar filename.jar

      This will extract jar file and create a new directory structure rooted under a directory named 'glassfish'.   

3)    cd glassfish

       Change Directory to GlassFish.

4)    If you are using a machine with an operating system that is a derivative of UNIX(tm), set the execute permission for the Ant binaries that are included with the GlassFish bundle.

      chmod -R +x lib/ant/bin
       lib/ant/bin/ant -f setup.xml

      OR for Windows:

      lib\ant\bin\ant -f setup.xml

5)     Start the server using the asadmin command. For that be maybe you first have to change the current directory to /glassfish/bin.

6)    next start the database

      asadmin> start-database

7)   and finally you can start the server...
       asadmin> start-domain domain1
      You can access your default page at


8) The server is now up and running. You can log into the web admin interface by the following url:


Login as Admin - userid="admin", password ="adminadmin"


Friday, December 14, 2007

Enable Directory Listings in Tomcat

Enable Directory Listings in Tomcat

We can enable Directory listings for applications when welcome files are mentioned.

For that we have to use web.xml in conf folder. The lines which are make bold with blue color do the tricks.


Virtual Hosting in Tomcat

Virtual Hosting in Tomcat

We can configure Virtual Hosting in Tomcat by simply adding Hosts in the server.xml file of Tomcat.

Here is the entry in the server.xml that configures Hosts in the Tomat.

 <Host name="" appBase="webapps" unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
    <Host name="" appBase="webapps" unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

After making an entry in the server.xml , restart  the Tomcat.

Finally add an entry in C:\WINDOWS\system32\drivers\etc\hosts file as follows    localhost

How to Execute Linux Machine Command using Java from Windows Operating System?

Here, In this example, we are execute Linux machine command using Java from windows operating machine.

In Java, This can be achieved using Command Prompt. To access any runtime (say DOS) we need an access to that Runtime. We can access runtime using Runtime class.

Runtime class has a static method called getRuntime() which returns Runtime object.
Then with exec() method we can have access to that runtime command.

To access Linux machine, we need plink - ( a command-line interface to the PuTTY back ends ) which can be downloaded from the following URL,

Here, Is the code snippet that will do the work.

class RuntimeTest
public static void main(String[] args)
Runtime runtime= Runtime.getRuntime ();

// Here , we have to access command line to run plink utility as well provide username , password and comman to execute on linux machine.

Process pro = runtime.exec("cmd /c plink.exe root@ -pw nki.6300 mkdir test13456");

// Wait for the result of process.

int i = pro.waitFor();


catch(Exception ex)