Computer Programming web Web programming Tips



How to create environment variables for Java and Tomcat

By Sergey Skudaev


When you installed Java SDK,Tomcat or some other software you have to create environment variables in Windows 8,10 or edit AUTOEXEC.BAT file in WINDOWS 95, 98, Me.

My AUTOEXEC.BAT file looks like this:

SET COMSPEC=D:\WINDOWS\COMMAND.COM

SET windir=D:\WINDOWS

SET winbootdir=D:\WINDOWS

SET PATH=D:\WINDOWS;D:\WINDOWS\COMMAND;C:\j2sdk1.4.0\bin;

SET PROMPT=$p$g

SET TEMP=D:\WINDOWS\TEMP

SET TMP=D:\WINDOWS\TEMP

SET CLASSPATH=.;C:\j2sdk1.4.0\lib;

C:\j2sdk1.4.0\bin; line required to be able to compile java source file regardless of its location. For example, if you place your Java source file. In "C:\Java\hello_word" directory, then in Command prompt you will go to hello_world directory and type javac + source file name with java extension. In my example file is Hello.java. Using PATH system will find javac.exe file in bin directory and compile java source file in class file with class extension.

Hover mouse over a thumbnail to see a large image.



compilation and execution java program

SET CLASSPATH=.;C:\j2sdk1.4.0\lib\classes; line points to location of java class files. Dot means that class file will be created in the same directory as source file. If system does not find class file in the same directory, then it will look in C:\j2sdk1.4.0\lib\classes directory. In my example Hello.class will be created in hello_world directory. To execute the java program you have to type java + class file name without extension. In my example it is java Hello. When program is executed Hello World is displayed on the command prompt. Below I show the Hello World source file. Note that class name is the same as file name. Public Class is Hello and file name is hello. This is not very interesting program, but you can use it to check your computer configuration. If you can compile and run the program, then everything is OK

Hello.java

import java.lang.*;

public class Hello
{
        public static void main(String args[])
        {
        System.out.println("Hello World");
       }
}

In WINDOWS 8 or 10 you do not use AUTOEXEC.BAT file. Instead you create environment variables. On your computer desktop right click the My Computer icon and select Properties.



environment variables - MyComputer properties

On the System Properties window select Advance tab.

Environment variables- System Properties

On Windows 7 select Start, right click Computer. Click Advance System setting on System properties window select Advance tab, Click Environment Variables button

On Windows XP, to get to the same System Properties window, select Start, Select Control panel,

In the opened Control panel select Performance and Maintenance (it is ar the bottom),

Control panel Performance and Maintenance

Select System, Advance tab.

Control, System, Advance tab

Control, System, Properties

Click the Environmental Variables button. Environment Variables window displays.

Control, System, Environment Variables

Click New button in System variables frame at the bottom of the Environment Variables Window. For Java SDK enter Path environment variable and.

Edit Environment Variables

enter path to JAVA bin folder on your PC. On mine it is C:\j2sdk1.4.0\bin. Type semicolon at the end. If you installed tomcat after java type path to tomcat bin folder on your PC. On mine it is C:\j2sdk1.4.0\bin;C:\jakarta-tomcat-4.1.29\bin;. Do not forget to type semicolon. Click OK button. Click OK button on Environment Variables window. Click OK button on Properties window.

To execute Java program create CLASSPATH environment variable.

CLASSPATH Environment variables

CATELINA_HOME Environment variables

For Tomcat enter CATALINA_HOME environment variable name and path to the folder where your tomcat installed. On mine it is C:\jakarta-tomcat-4.1.29

JAVA_HOME Environment variables

To run Tomcat you need to create JAVA_HOME environment variable. To check your configuration for Tomcat go to C:\jakarta-tomcat-4.1.29\bin directory, type startup and press enter.

Start Tomcat Environment variables

Tomcat starts in separate command prompt window.

Environment variables Tomcat is running

If Tomcat does not start, probably you have not enough memory set in command prompt. Go to command prompt menu on your desktop and right click it

MS DOS Prompt Environment variables

From drop down menu select properties. Select memory tab. Increase convention memory and click OK to save changes.

MS DOS Prompt Environment variables

Close command prompt if you had it open. Open again and try to start Tomcat.

Now it should be started. To make sure that Tomcat is running properly, open Internet Explored and type URL address:

http://localhost:8080

Tomcat home page displays.

Tomcat home page Environment variables

Click JSP or Servlet Examples link. Play with examples and have fan!

JSP examples Environment variables




My eBooks on Amazon.com

US    UK    BR    CA
US   UK   BR   CA
US    UK    BR    CA