File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Classpath............ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath............" Watch "Classpath............" New topic


Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129

I want to run Java, JSP and Servlets. For that we are setting the enviornment variables. Instead of setting the enviornment variables in
My Computer (right click)>> properties >> advanced, is there any other way to set it.
Shortly, I don't want to change any settings in the System(since it has some sensitive datas). Is there any possibility of using the bat file for that. If so, please suggest or give example on how to creat a bat file.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

You can set environment variables in the command prompt window using the "set" command, for example:

set CLASSPATH=C:\directory\servlet.jar;.

Creating a bat file is very simple, just use a text editor (Notepad for example), type the commands and save it with the extension ".bat".

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Steve Simon Joseph Fernandez
Ranch Hand

Joined: Jul 17, 2005
Posts: 35
Actually, system-wide classpaths are evil. Do not use them. Instead, for every development enviroment or project that you have, write a batch (.bat) file or a shell script, put all your classpaths and other variables there, and execute it before you start working on that project. This way, you can work on multiple projects at one go and be absolutely sure that each project has the proper and local settings.

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 694
How are you accessing the Environment variables from your java program?
I use a real cludge of a program that uses Runtime exec() with SET and traps the console output. UGLY!
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 694
Or is this a question of how to set the classpath for an invocation of the JVM? Nothing to do with the general question of environment variables.
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129

I written the following in the notepad and saved it as startup.bat:
SET PATH = "C:\jdk1.3\bin;"

When I clicked the startup.bat (or) thru MSDOS I typed startup.bat, one screen came & gone quickly, nothing is happening.
For example: In the dos prompt, I typing the below thing
E:\>SET PATH="C:\JDK1.3\bin;" .

After that, when I typed as below, the got following:

Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-O Optimize; may hinder debugging or enlarge class file

-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are us
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-target <release> Generate class files for specific VM version

But I have to set the path, whenever I am rebooting the system. In order to avoid it I want to write the bat, but it not working. How to resolve it? (In the bat file, i am going to have Path,classpath,java_home,etc..)
[ September 07, 2005: Message edited by: Niyas Ahmed Sheikh ]
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Please read and complete the following: Your First Cup of Java
I agree. Here's the link:
subject: Classpath............
It's not a secret anymore!