First: Sorry for the title but i was really not sure how to frase the question.
I have a maven project with several modules in it. All the modules are really simple as they provide some special logic classes to the main Web-App module. These logic classes are injected at runtime by spring.
Following is my Maven setup (abstracted for simplicity)
- core-module (provides interfaces and basic classes for all modules)
- algorithm-modules (modules which provide special algorithms, implement one of code-modules interfaces)
- web-app-module (Spring Web App, which uses the algorithms that register themselves as @Component, is dependent on core and algorithm modules)
Now the Problem: The algorithm module has a resource - in this case a python script - which i want to execute on the systems Python interpreter. (resource/pythonscript.py)
All available Algorithm Classes (Implement Metric interface) are injected by spring in to the web-apps controller:
@Autowired
List<Metric> metrics;
Later the user chooses the algorithm he wants to execute:
metric.performCalculations(dataset);
This executes the logic that later tries to run the python script from the modules resource directory:
URL url = NXBetweennessCentrality.class.getResource("bc/betweenness_centrality.py");
logger.debug("URL: {}", url); //=> null
I tried sevaral combinations:
class.getResourceAsStream(resourcePath)
class.getClassLoader().getResources("")
basically everything from How do I load a file from resource folder? But i can't load this resource.
I heard of problems when trying to access resources of a maven dependencys project (Use a dependency's resources?), but in my case i execute the Class from the package which owns the resource - so there should be no problem, at least thats what i thought.
Can somebody point out my mistake? Is this not possible without some tricky workaround?