Reputation: 1
I'm currently working with Drools 7.73.0, and seem to be running into a file lock issue when adding a KieModule to KieServices repository, using just a file path to a kjar file that exists on a local file system. It appears that the file path resource needs to be closed after adding it to the repository, however there does not appear to be a close method available.
The code I am currently using to load the kieModule from the kjar file into the repository is as follows:
String pathKjar = "pathToKjarFile.kjar";
...
KieServices ks = KieServices.Factory.get();
Resource resource = ks.getResources().newFileSystemResource(pathKjar);
ks.getRepository().addKieModule(resource); //<-- pathKjar is locked at this line
KieContainer kc = ks.newKieContainer(releaseId);
...
File testFile = new File(pathKjar);
testFile.delete(); //<-- pathKjar is still locked, delete always returns false
As noted above, the line of code ks.getRepository().addKieModule(resource);
puts a lock on the resource, while it is in use, however I have not been able to find a way to close the resource afterwards, leaving the resource open.
What is the proper way to close the Resource?
Note, I was able to use an inputstream to accomplish the same thing, and the resource does close successfully using that method, and all seems to work as expected. This question is solely on how to properly use newFileSystemResource with a String path to the file location, and ensure there are no resource leaks.
Upvotes: 0
Views: 193
Reputation: 13768
I've tried to reproduce the problem that you're reporting but in all honesty I couldn't. In particular I quickly modified this example by putting the jar file returned by the getFile()
method into a variable before passing it to the newFileSystemResource()
one. Then trying to delete that file at the end of the test works as expected for me and returns true
.
In case this problem persists I suggest you to open a ticket in the Drools tracking system and attach a complete reproducer.
Upvotes: 0