1

I have shapefiles in my resources directory and see them in the jar. After executing my service, the logger in OpenShift shows this: "Read lock: file:/opt/app-root/src/file:/opt/app-root/src/mars-de-service.jar!/BOOT-INF/classes!/CountryBoundaries.shp)". This tells me that it is able to find it and read it. In fact, in my local environment, the file is actually processed. However, in OpenShift, the next line in the logger shows this: "java.lang.RuntimeException: java.io.FileNotFoundException: /opt/app-root/src/file:/opt/app-root/src/mars-de-service.jar!/BOOT-INF/classes!/CountryBoundaries.shp (No such file or directory)". In my local, as I mentioned, I don't get such an error and my service works fine.

Below is my code:

URL res = CountryCodeLookup.class.getClassLoader().getResource("CountryBoundaries.shp");    
File sourceFile = new File(res.getFile());
store = FileDataStoreFinder.getDataStore(sourceFile);
featureSource = store.getFeatureSource();
GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
attrName = geomDesc.getLocalName();

What am I missing?

0

1 Answer 1

1

I found a solution by changing URL to URI and then doing a toURL(). See below:

URI sourceFile = new ClassPathResource("PoliticalSubdivisionBoundaries.shp").getURI();
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile.toURL());
featureSource = store.getFeatureSource(); 
GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
attrName = geomDesc.getLocalName(); 

Shapefiles are complex and cannot be accessed the usual way like using inputStream and such.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.