Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Java classpath separator?

Tags:

java

classpath

How to programmatically get Java classpath separator used in value of java -cp/-classpath option?

like image 694
czerny Avatar asked Oct 16 '25 13:10

czerny


2 Answers

System property path.separator contains classpath separator for current platform. It can be obtained by

System.getProperty("path.separator");

From System.getProperties() documentation:

path.separator Path separator (":" on UNIX)

Values are : for Linux and Mac OS, ; for Windows.

like image 155
czerny Avatar answered Oct 19 '25 02:10

czerny


For this purpose, you can rely on the constant File.pathSeparatorChar if you expect a char or File.pathSeparator if you expect a String.

I quote the Javadoc of File.pathSeparatorChar:

The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.

like image 27
Nicolas Filotto Avatar answered Oct 19 '25 02:10

Nicolas Filotto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!