Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the default classpath when not specifying classpath?

Tags:

java

Wondering what will be the default classpath when not specifying classpath option?

like image 214
user705414 Avatar asked Nov 22 '11 13:11

user705414


People also ask

What is default classpath in spring boot?

By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath.

What should classpath be set to?

The default value of CLASSPATH is a dot (.). It means the only current directory searched. The default value of CLASSPATH overrides when you set the CLASSPATH variable or using the -classpath command (for short -cp). Put a dot (.)

How do I find out my classpath?

To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.


2 Answers

The current working directory (.).

From The Java™ tutorials: PATH and CLASSPATH:

The default value of the class path is ".", meaning that only the current directory is searched. Specifying either the CLASSPATH variable or the -cp command line switch overrides this value.

Does this include subdirectories?

No, no entry in the classpath is "recursive". You have to list each subdirectory (or jar) explicitly. However, if you have an Example.class file representing class pkg.subpkg.Example, and the default classpath is used, then this file should live in ./pkg/subpkg/Example.class.

If java attempts to resolve pkg.subpkg.Example it will look in /pkg/subpkg of each classpath entry. I.e. you do not have to list ., pkg, and pkg/subpkg in the classpath, only ..

like image 134
aioobe Avatar answered Sep 20 '22 13:09

aioobe


I think people are answering this person's question too literally. Yes, CLASSPATH defaults to ".", but there are a bunch of classes that automatically get loaded even when you don't set CLASSPATH or use the -classpath command line argument.

The following is a good place to learn about this process:

http://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html

like image 22
gilbertpilz Avatar answered Sep 21 '22 13:09

gilbertpilz