Let's say I have a java file C:\workspace\project\src\packagename\foobar.java
. Now, I would like to compile this file at runtime, but for that I need the corresponding .classpath
file (or rather, it's entries), located at C:\workspace\project\.classpath
, so that I can pass the dependencies with the -classpath
argument (this approach works if I hard-code it, but that's obviously only proof-of-concept, not the goal).
How would I go about finding the .classpath
file?
My idea was walking the file tree bottom up, starting at foobar.java
, until I get to a level where a .classpath
file exists which I can then use.
However, I'm a) not sure that this is the way to do it, and b) not sure how to walk the file tree bottom up, other than String.split
-ting the file and removing the segments, starting at the end. That is super ugly, though, and I refuse to believe that there is no better option.