Questions tagged [classpath]

In Java, the classpath tells the Java Virtual Machine where to look for user-defined classes and packages when running Java programs. The classpath is a parameter and can be set either on the command-line, or through an environment variable.

When executing Java programs, the JVM uses a method that is similar to classic dynamic-loading. That is, the JVM lazily finds and loads classes (meaning, the JVM loads a class only when it is first used). The classpath tells the JVM where to look for the files that define these classes, on the filesystem.

The JVM searches for and loads classes in the following order:

  • Bootstrap classes: These are fundamental classes belonging to the Java platform. These are public classes that belong to the Java Class Library, and it also includes the private classes that are necessary for this library to function properly.
  • Extension classes: These are packages that are in the extension directory of either the JRE or the JDK (usually in jre/lib/ext/).
  • User-defined packages and libraries: These are packages and libraries that are created by the user or that are being used by the user. These can include third-party libraries.

Packages from the JDK standard API and extension classes are accessible by default (the classpath doesn't need to be explicitly set to provide access to them). However, the path for all user-defined packages and libraries must be set. This can be done either via the command-line, an environment variable, or in the manifest file associated with the JAR file that contains the classes.

4839 questions
65
votes
9 answers

Execute jar file with multiple classpath libraries from command prompt

I have a Maven project which generates a jar file and copies all dependencies to target/lib folder. I want to execute this project on client's machine (windows). So, I copied myproject.jar to C:\xyz folder and all dependencies to C:\xyz\lib…
Praneeth
  • 1,457
  • 5
  • 23
  • 36
64
votes
3 answers

Java: Which of multiple resources on classpath JVM takes?

If I have multiple files of the same name on classpath (e.g. I have multiple .jar with log4j.properties), what are the rules JVM follows to chose one?
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
64
votes
6 answers

How do you change the CLASSPATH within Java?

How do you change the CLASSPATH of a Java process from within the Java process? Before you ask me "Why would you want to do that?" I'll explain it shortly. When you have a Clojure REPL running it is common to need more jars in your CLASSPATH to…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
64
votes
11 answers

How do I define a compile-time *only* classpath in Gradle?

Can someone please give me a simple build.gradle example of how I can specify compile-time-only classes that are not included in the runtime deployment (war). Gradle seems to have gotten this the wrong way around since 'runtime' inherits from…
Alex Worden
  • 3,374
  • 6
  • 34
  • 34
63
votes
12 answers

Remove project .jars from project explorer view in Eclipse

The list of jars just takes up too much space. Can I collapse it or hide it?
flybywire
  • 261,858
  • 191
  • 397
  • 503
62
votes
24 answers

Why does ANT tell me that JAVA_HOME is wrong when it is not?

I get the error: C:\dev\ws\springapp\build.xml:81: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\Program Files\Java\jre6" But I have…
Ankur
  • 50,282
  • 110
  • 242
  • 312
61
votes
11 answers

Where is the correct location to put Log4j.properties in an Eclipse project?

Where in my Eclipse project should I add the log4j.properties file so that it will work as intended?
Srinivas Reddy
  • 629
  • 1
  • 7
  • 9
60
votes
5 answers

How to place a file on classpath in Eclipse?

As this documentation says, "For example if you place this jndi.properties file on your classpath", but how can I place the .properties file on my classpath if I am using Eclipse?
Cacheing
  • 3,431
  • 20
  • 46
  • 65
59
votes
10 answers

Java project: should .classpath .project file be committed into repository?

Should I check in my .project and .classpath files? My friend told me that I should only check in .java files and the build.xml to guarantee portability. He said ".classpath will cause you much less portability on different environment. .project is…
sean
  • 817
  • 2
  • 9
  • 7
57
votes
2 answers

Is WEB-INF in the CLASSPATH?

Is the WEB-INF folder in the CLASSPATH of a Java Web application?
Shyam Kumar Sundarakumar
  • 5,649
  • 13
  • 42
  • 69
56
votes
4 answers

adb is not recognized as internal or external command on windows

I set the c:/android-sdk/tools path to the path environment and commands like emulator is working just fine. But the adb command is still not recognized, what should I do ? In the path system variable I added the android-sdk path and the tools path…
Lukap
  • 31,523
  • 64
  • 157
  • 244
56
votes
9 answers

How do I include jars in a groovy script?

I have a groovy script that needs a library in a jar. How do I add that to the classpath? I want the script to be executable so I'm using #!/usr/bin/env groovy at the top of my script.
timdisney
  • 5,287
  • 9
  • 35
  • 31
53
votes
13 answers

How to set a long Java classpath in Windows?

I'm trying to run a particular JUnit test by hand on a Windows XP command line, which has an unusually high number of elements in the class path. I've tried several variations, such as: set CLASS_PATH=C:\path\a\b\c;C:\path\e\f\g;.... set…
Ogre Psalm33
  • 21,366
  • 16
  • 74
  • 92
52
votes
2 answers

Set folder for classpath

From the command line, how do I set the Java CLASSPATH option to point to one or more directories containing multiple jar file? Are there wildcards for recursive directory and sub-directory support? (My JAR files are sorted in several…
Sam
  • 6,770
  • 7
  • 50
  • 91
52
votes
5 answers

Loading velocity template inside a jar file

I have a project where I want to load a velocity template to complete it with parameters. The whole application is packaged as a jar file. What I initially thought of doing was this: VelocityEngine ve = new VelocityEngine(); URL url =…
Rafael
  • 2,373
  • 4
  • 22
  • 28