Juan Moreno
Juan Moreno

Reputation: 2795

How to print the current classpath with kotlin?

I need to print the current classpath in a Kotlin program. What alternatives are?

My application is package in a jar file and I using Kotlin 1.3.61 and OpenJDK 8.

Upvotes: 2

Views: 4528

Answers (1)

Juan Moreno
Juan Moreno

Reputation: 2795

We can use:

(java.net.URLClassLoader.getSystemClassLoader() as java.net.URLClassLoader).getURLs().forEach({println(it.getFile())})

Or

println(System.getProperty("java.class.path"))

But there behave with differences, more details here: What's the difference between System.getProperty("java.class.path") and getClassLoader.getURLs()?

Upvotes: 5

Related Questions