Load OSM File from Classpath instead of Filesystem

my question is related to importOrLoad() function in Graphhopper.class.
Instead of loading the osm file from the file system, I want to include the osm file and related graph directory directly in my application jar package. This is needed since only one jar file can be distributed within my cluster system.
Is it possible to import the OSM File from the classpath and not from the filesystem?

So far I tried to use a URL beginning with “classpath:” but this results in following error.

Exception in thread “main” java.lang.RuntimeException: Directory classpath:\osm\bayern-latest\bayern-latest.osm-gh does not exist and cannot created to place lock file there: classpath:\osm\bayern-latest\bayern-latest.osm-gh\gh.lock

Graphhopper can’t get the Filesystem lock, since the classpath is read only access.

Any idea?

GraphHopper has to build the graph from an OSM file which it tries to store on the disk. You could change that behavior, if it’s only a small osm file the import should be fast. Otherwise you might be able to import the graph locally and put the graph files into the jar and change some write lock settings.

In any way, I would recommend not including the osm file nor the graph folder, as I think both solutions are not really clean. Rather download the osm file on the server and go from there. That’s probably how I would do it.