Is the current path `.` in the classpath by default?

Solution 1:

From Oracle's page on setting the class path:

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

Use ; for Windows and : for Unix-like operating systems as a separator for multiple paths.

Solution 2:

If you add classpath then current path is omitted, which is a very very unpleasant and unexpected behavior :(

Moreover to add current path I found (at least for ubuntu) that IT IS NOT ENOUGH to add . in classpath but you have to add ./*

For example (this will not work)

java -ea -cp ".:lib/*" org.testng.TestNG suites/regression.xml

will NOT work if you have a jar file in current path

the correct one is

java -ea -cp "./*:lib/*" org.testng.TestNG suites/regression.xml

I hope no one shoots himself or have a heart attack!

Solution 3:

Do the second command add the current path as another path for searching?

Yes

Is it the correct way to separate multiple paths, by a colon?

depends on platform, in unix platform : works, in windows you need ;

Isn't the current path always in ClassPath by default, and thus no need to explicitly specify?

Current directory is present by default unless you override it with -cp in first case it is not present in second case it is

Solution 4:

From the help page (FOR WINDOWS):

-classpath classpath
-cp classpath

    Specifies a list of directories, JAR files, and ZIP archives to
    search for class files. Separate class path entries with semicolons
    (;). Specifying -classpath or -cp overrides any setting of the
    CLASSPATH environment variable.

    If -classpath and -cp are not used and CLASSPATH is not set, then the
    user class path consists of the current directory (.).

Note that, on windows, the path separator is a ; semicolon.

On other platforms the separator is the colon :.

This conforms with the standard path-like systems on the various platforms.