karmapolice
karmapolice

Reputation: 336

eclipse dynamic web project: accessing static files without using servletContext

I have read this question about accessing static files in a dynamic project: Where to place a directory of static files in Eclipse Dynamic Web Project

and the only answer suggests using the method getRealPath from ServletContext.

I have a dynamic project in which a regular Java class (not a servlet, not a JSP) must access a static file with a fixed path. This class is called from a JSP, but throws a FileNotFound exception, no matter where I put this file (project root, WebContent folder...).

Is there a way for this class to access to a static file in a dynamic web project by its own, without having to receive the 'real path' from a servlet? What is the proper way to do this?

Thank you very much.

This are the lines where the class access the static files:

System.setProperty("javax.net.ssl.trustStore","trust.jks");
System.setProperty("javax.net.ssl.keyStore","cliente.jks");

I tried putting them under the root directory, WebContent, WebContent/WEB-INF and WEB-INF/lib.

I guess absolute paths will work, but I do not think is a good idea.

The root exception is:

java.io.FileNotFoundException: cliente.jks (El sistema no puede hallar el archivo especificado)
    java.io.FileInputStream.open(Native Method)
    java.io.FileInputStream.<init>(Unknown Source)
    java.io.FileInputStream.<init>(Unknown Source)
    sun.security.ssl.SSLContextImpl$DefaultSSLContext$2.run(Unknown Source)
    sun.security.ssl.SSLContextImpl$DefaultSSLContext$2.run(Unknown Source)
    java.security.AccessController.doPrivileged(Native Method)
    sun.security.ssl.SSLContextImpl$DefaultSSLContext.getDefaultKeyManager(Unknown         Source)
    sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(Unknown Source)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

Upvotes: 0

Views: 2037

Answers (1)

Manohar Ch
Manohar Ch

Reputation: 465

If the static files are there in the web application related folders then by using relative path you can access those static files, otherwise absolute path.

Upvotes: 0

Related Questions