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.


       http://java.net/download/javaee5/v2_branch/promoted/Linux/glassfish-installer-v2-b58g.jar

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

http://localhost:8080/


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

http://localhost:4848

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.

    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>


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="www.nitinroman.com" appBase="webapps" unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
    </Host>
   
    <Host name="www.sachinroman.com" appBase="webapps" unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
    </Host>


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

127.0.0.1    localhost
127.0.0.1    www.nitinroman.com
127.0.0.1    www.sachinroman.com




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,

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

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


class RuntimeTest
{
public static void main(String[] args)
{
try
{
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@192.168.0.247 -pw nki.6300 mkdir test13456");

// Wait for the result of process.

int i = pro.waitFor();

if(i==0)
{
System.out.println("Exceuted");
}

}
catch(Exception ex)
{
System.out.println(ex);
}
}
}