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

Classpath problem

surendar bandi

Joined: Jul 26, 2006
Posts: 2
Can anyone pls help in knowing, where the classpath enviroment variable value is set to.


I have Test.class file. Is there any way to run this file using "java Test" command, without setting classpath to to current directory by explicitly setting path by one of the following ways..

1. setting classpath in particular command prompt
2. setting classpath by going to System "Environment Variables".

My exact question is.. Is there any file comes with JRE or J2SDK where the classpath has set to (".;") current directory. If any file is there ..pls let me know..

Thanks in Advance..
-Surendar reddy Bandi.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Is this a specific SCJP issue you have, or is it a general question about classpaths?

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
surendar bandi

Joined: Jul 26, 2006
Posts: 2
It is general question i am asking about. I would like to know, from where JVM will take classpath as current directory. Pls let me know ur suggestions.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
There are plenty of options to set the an application class path.

1. The first would be setting the class path directly in the Java Application Launcher using the flag -cp or -classpath.

In Windows:

> java -cp .;C:\MyApp\libs\myLib.jar com.javaranch.MyApp

In Linux:

> java -cp .:/home/myApp/libs/myLib.jar com.javaranch.MyApp

2. A secod option could be setting the classpath in an environment variable. This can be done just before calling you app or it could be made permanently in the OS. In Windows you can do that temporarily declaring the variable with the SET command, whereas in Linux you can use the export command.

3. In this same line of thinking you can write your CLASSPATH variable permanently in an environment variable. In Windows do so by right clicking on the My Computer->Advanced->Environment Variables->User Variables. In Linux declare the variable in the profile .bash_rc or environment files.

4. Another option is to create a jar file and in the manifest of the file declare the property Class-Path property of the manifest.

5. Another option could be to create a batch file or an script file where you either declare the environment variable or pass it to the java application launcher in the -cp flag. In this latter case you simply invoke the batch or script file and the java application will execute.
I agree. Here's the link:
subject: Classpath problem
It's not a secret anymore!