Sunday, February 24, 2013

Installing and Configuring Apache Tomcat Server

Downloading Apache Tomcat
  • Download the latest version of Apache tomcat viz. Apache Tomcat 7 from Tomcat 7 
  • According to your system configuration download the appropriate version.
  • I'm showing you for Windows 7 32-bit configuration viz. apache-tomcat-7.0.34-windows-x86.zip
  • Extract it in appropriate folder viz. C :\.
Setting up JDK Path 
  • Create an environment variable "JAVA_HOME" as follows
    • Click Start, right click on Computer and select Properties.
    • Select Advanced System Setting , click on Environment Variables.
    • In the User Variables Pane click on New .
    • In Variable name write JAVA_HOME and in Variable value give the address of JDK installation directory viz. if your java is installed inside program file of c:\ then give the address up to JDK1.6 directory.
 
Apache Tomcat Overview
  • The folder structure after extracting is shown below.
    • bin: Contains startup.bat for starting Tomcat and shutdown.bat for stopping the Server.
    • conf: Contains server.xml for adjusting Server configuration like port number, host name etc., tomcat-users.xml for adjusting user roles for authentication, web.xml i.e the deployment descriptor.
    • lib: Contains library files for supporting web applications viz. servlet-api.jar for Servlet application.
    • webapps: This is for application deployment. This contains actual project may be in .war file or in normal folder structure.
Adjusting Server Configuration
  • Typical server.xml contains information about server port, connector port, protocol, redirect port etc. If you want to change the corresponding ports u can change by editing it with your favorite WYSIWYG  editor. Normally you need to change the connector port if you have installed Oracle database because Oracle takes 8080 port.

    • server port:
    • connector port & redirect port:

  • Typical tomcat-users.xml contains information about users information i.e login information for manager status admin GUI etc.
    • First Leave this step and go to Start the Server step.
    • Original Content of tomcat-users.xml file given below

    • Change the content of this by the following line. This is actually new feature in version 7.
<role rolename="tomcat"/>
 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
 <role rolename="manager-jmx"/>
 <role rolename="manager-status"/>
 <role rolename="admin-gui"/>
 <user username="tomcat" password="tomcat" roles="tomcat"/>
 <user username="tomcat" password="tomcat" roles="manager-gui"/>
 <user username="tomcat" password="tomcat" roles="manager-script"/>
 <user username="tomcat" password="tomcat" roles="manager-jmx"/>
 <user username="tomcat" password="tomcat" roles="manager-status"/>
 <user username="tomcat" password="tomcat" roles="admin-gui"/>
 <user username="admin" password="admin" roles="tomcat,manager-gui,manager-script,manager-jmx, manager-status,admin-gui"/>
    • Make sure to remove comment line before replacing this above content.

Starting the Server

  • Start the server by double clicking on startup.bat present in the bin folder.
  • Open your favorite browser viz. Mozilla Firefox  and type http://localhost:8090/ and hit enter.
  • If you get this screen then congratulation...
  • Now if you click on either "Server Status, Manager App, Host Manager", it will ask you for authentication. Now go to previous paragraph where we skipped earlier with tomcat-user.xml configuration.
  • Now put username as admin and password as admin and press enter and congratulation again...        
Developing Web Application
  • Develop your web project and put it in webapps directory and access it..
  • In another blog i will show you how to develop servlet application and deploy it in Tomcat Server.

Friday, February 22, 2013

Create a .EXE file from a .JAR file

     The output of a java program is a .class file unlike the output of C program i.e .exe file. So, it is easy to execute a C program but to run a java program you need java command. In a bigger view we address the .class files into an executable .jar(Java Archive) file. So just imagine if we convert the .jar file into an .exe file, how seamlessly we can execute a program, just double click on it and run the program. So to perform this task we have many free software tools available, out of this Lunch4j  is one of the tool. Now i am going to show you a simple demo using it.

Step-1:
    Download the Launch4j software from Launch4j. You can download .exe file or .zip file as per your wish. But, I recommend you to download the launch4j-3.1.0-beta1-win32.zip.
Step-2:
   Extract the file and save it in appropriate location.The folder structure is shown below.
Step-3
  Lunch the lunch4j.exe application by double clicking on it. A window opens like given below
Step-4
 Fill the required fields as follows in the Basic tab.
 Output file: It's your required .exe file.
 jar: It's your created .jar file.
 For the demo purpose i have used the demo jar file available in JDK installation directory.
 You can also fill the optional fields like icon , Priority etc.
Step-5
If you try to save it now you will find an pop up window like below
So go to JRE tab and fill the minimum JRE version according to your JDK installation viz. 1.6.0_14 for simplicity.
Step-6
     Save Configuration by clicking the   button.The Configuration file is saved as .xml or .cfg file. You can edit that in your favorite XML editor viz Notepad ++.
Step-7
     Click the Build Wrapper button  to convert the .jar to .exe . You can see the log file
   That's all you have successfully created the .exe file.
Step-8
 Execute the .exe file created by double clicking on it to watch Java 2D Demo.
 Step-9
  The Content of the .xml file is shown below.
Step-10
  Let's check the other tabs like Classpath, Header etc. which is self explanatory.

                             I hope you will enjoy it.