1

Here I am try to get the file urls dynamically to set to compiler in code. I'm using code to get those by casting the class loader got from thread context and then cast it to UrlclassLoader and then call getUrls method. But in Java 10 it is not supported as per documentation. Is there any alternative for this?

Naman
  • 27,789
  • 26
  • 218
  • 353
  • May be some other approach to get urlclasspath for classpath jars. – Kartik Parihar Jun 20 '18 at 17:57
  • Could you share some code to show what exactly are you trying to achieve? I am pretty sure there are similar question with java-9 tags you can lookup for. If they still do not cover your use case, please elaborate. – Naman Jun 20 '18 at 18:56
  • Here is the same code : UrlclassLoader ul = (UrlclassLoader) Thread.currentthread().getcontext.getclassLoader(); URL urls[] = UL.geturls(); urls[] needed for further processing – Kartik Parihar Jun 20 '18 at 20:05
  • 1
    https://stackoverflow.com/questions/49557431/how-to-safely-access-the-urls-of-all-resource-files-in-the-classpath-in-java-9-1 – Stefan Zobel Jun 20 '18 at 20:40
  • 1
    @KartikParihar You will find the answers to [How to safely access the URLs of all resource files in the classpath in Java 9/10?](https://stackoverflow.com/questions/49557431/how-to-safely-access-the-urls-of-all-resource-files-in-the-classpath-in-java-9-1) solve your problem, particularly [this one](https://stackoverflow.com/a/49557901/2525313). – Nicolai Parlog Jun 21 '18 at 06:35
  • You still didn’t say what you want to do with this URLs. Until you describe your “further processing”, I consider your question a typical xy-problem. – Holger Jun 21 '18 at 08:56
  • Thanks for the answers. I consider the approaches provided and it worked for me. – Kartik Parihar Jun 22 '18 at 14:34
  • I have written a maven mojo to compile JSP file, this need to update the classpath at runtime with file urls. And set it to mojo compiler. – Kartik Parihar Jul 28 '18 at 11:04
  • As of now there's no dynamic values updated in class path. So, I have used the similar response as mentioned by @Nicolai. – Kartik Parihar Jul 28 '18 at 11:06

0 Answers0