Improved java resource handling