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
51
votes
9 answers

How to connect SQLite with Java?

I am using one simple code to access the SQLite database from Java application . My code is import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ConnectSQLite { …
Rajapandian
  • 9,257
  • 24
  • 74
  • 86
50
votes
3 answers

Dynamically loading plugin jars using ServiceLoader

I'm trying to create a plugin system for my application, and I want to start with something simple. Every plugin should be packed in a .jar file and implement the SimplePlugin interface: package plugintest; public interface SimplePlugin { …
MaxArt
  • 22,200
  • 10
  • 82
  • 81
50
votes
9 answers

Android - Command not found

I am trying to run the command in ubuntu android update project --path . However I am getting a android:command not found error. I assume this is something to do with the path which I learnt on here the other day? I was just wondering, what do…
Biscuit128
  • 5,218
  • 22
  • 89
  • 149
49
votes
9 answers

spark submit add multiple jars in classpath

I am trying to run a spark program where i have multiple jar files, if I had only one jar I am not able run. I want to add both the jar files which are in same location. I have tried the below but it shows a dependency error spark-submit \ --class…
Avinash Nishanth S
  • 514
  • 1
  • 5
  • 15
47
votes
6 answers

Eclipse: How to build an executable jar with external jar?

I am trying to build an executable jar program which depends on external jar downloaded. In my project, I included them in the build path and can be run and debug within eclipse. When I tried to export it to a jar, I can run the program but I can't…
Ben
46
votes
2 answers

How do I set the classpath in NetBeans?

Can someone tell me where and how I set the classpath in NetBeans? I would like to add a .jar file.
Borut Flis
  • 15,715
  • 30
  • 92
  • 119
46
votes
2 answers

What's the difference between a System property and environment variable

I am not clear about this. When I run a java App or run an Applet in applet viewer, (in the IDE environment), System.getProperty("java.class.path") gives me the same as System.getenv("CLASSPATH") which is the CLASSPATH defined in my env…
Khue Vu
  • 3,112
  • 4
  • 37
  • 40
46
votes
11 answers

Android Studio 'tools.jar' file is not present in classpath

I downloaded the current version of Android Studio (latest as of 4th July 2013) I also downloaded the JDK version 7u25. However, it displays error after startup: Please ensure JAVA_HOME points to JDK rather than JRE. I don't know how to solve this…
axolotl
  • 1,042
  • 1
  • 12
  • 23
44
votes
14 answers

Javah error while using it in JNI

Command: javah -jni JavaHowTo Result: error: cannot access JavaHowTo class file for JavaHowTo not found javadoc: error - Class JavaHowTo not found. Error: No classes were specified on the command line. Try -help. I have set the class path…
krishnakumar
  • 2,187
  • 5
  • 21
  • 24
44
votes
4 answers

Maven classpath order issues

Does anyone know of a way to set a specific classpath order in Maven2, rather than the random ordering I appear to experience at the moment? There are a number of legitimate reasons for wanting to do this: A vendor has supplied a patch jar, which…
Brett Hannah
  • 4,307
  • 4
  • 30
  • 33
44
votes
3 answers

Getting Ant to recognise a classpath

I have an Apache Ant build file with a command that requires four specific JARs to be on the build classpath. I've tried to do this:
Paul Fisher
  • 9,618
  • 5
  • 37
  • 53
42
votes
2 answers

How to read several resource files with the same name from different JARs?

If there are two JAR files in the classpath, both containing a resource named "config.properties" in its root. Is there a way to retrieve both files similar to getClass().getResourceAsStream()? The order is not relevant. An alternative would be to…
Zeemee
  • 10,486
  • 14
  • 51
  • 81
42
votes
2 answers

include external jar when running java -jar

From my readings, when you execute a command as follows: java -jar foo.jar Then the main classpath is ignored, and the classpath is taken from the manifest file. Further, the classpath declared on the command line is also ignored. So in: java…
rouble
  • 16,364
  • 16
  • 107
  • 102
42
votes
8 answers

How do I increase the /proc/pid/cmdline 4096 byte limit?

For my Java apps with very long classpaths, I cannot see the main class specified near the end of the arg list when using ps. I think this stems from my Ubuntu system's size limit on /proc/pid/cmdline. How can I increase this limit?
user27635
  • 423
  • 1
  • 4
  • 4
42
votes
5 answers

Running java in package from command line

I have read the previously posted questions. Some are vague and none solved my problem so I am forced to ask again. I have two simple classes, package One; import One.Inner.MyFrame; public class test { public static void main(String args[]) …
user2756339
  • 685
  • 1
  • 10
  • 17