How to get getclass().getResource() from a static context? How to get getclass().getResource() from a static context? java java

How to get getclass().getResource() from a static context?


The main method is a static method, so trying to access this (= the current Object) will not work.You can replace that line by

URL keyFileURL = SecureFTP.class.getClassLoader().getResource("/home/xxxxx/.ssh/authorized_keys");


Old question but this hasn't been said yet. You can do this from a static context:

ClassLoader classLoader = ClassLoader.getSystemClassLoader();classLoader.getResource("filename");