Java class resources as stream
When you create projects (Java or Java web project) in eclipse and you want to add resources,
you must know that there are difference between to Java project and Java web projects.
Because the web projects is buliding class and storing them in WEB-INF/classes/ and the eclipse won't put you resources in classes/ folder,
as the are in doing when you building standard Java project.
So this is how I did it, i create folder RES inside WEB-INF/ and put files in that folder. And in code I put this to load that resources.
Java web projects:
ServletContext context = getServletContext();
String path = "WEB-INF/RES/";
InputStream ksStream = context.getResourceAsStream(path + KEYSTORE_RESOURCE_NAME);
InputStream pkStream = context.getResourceAsStream(path + CERT_RESOURCE_NAME);
and this is how I did it in standard Java projects
InputStream pkStream = MyClass.class.getResourceAsStream(KEYSTORE_RESOURCE_NAME);
InputStream pkStream = MyClass.class.getResourceAsStream(CERT_RESOURCE_NAME);
Comments
Post a Comment