简体   繁体   中英

Using JAR resource as File in java or scala

I have developed an application that basically searches its resources/runtime directory, looking for .java files.

Having fetched all .java sources, it (together with program arguments) passes their absolute paths to JavaCompiler .

Of course, this approach doesn't work when application is deployed as a JAR package. So the question - how can I work with resource files as with regular files, ie pass their absolute path and read them afterwards?

I found some related topics here:

But what if I don't know names of the files? I seek solution that allows me to search the resources/runtime directory. Moreover, I think making a copy of file somewhere and delete it later on is clumsy solution.

I use combination of Java and Scala (with sbt build system), hence solution Java or Scala would be great.

Refer to this and see if it answers your question.

Edit: How do I list the files inside a JAR file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM