Skip to content
Advertisement

assets folder is not accessible in java class Tomcat Web Project Built in Maven

I have tried to make assets folder in different locations in the project and I have MS Access DB file in it. I want to access it using ucanaccess driver. but it gives file not found exception.

DB connectivity code.

JavaScript

but with this code, it is working fine

JavaScript

I tried to put assets folder under the project main folder, java folder, webapp folder and WEB-INF folder.

I also tried in NetBeans IDE.

Advertisement

Answer

The path .assetsBC190201004.accdb you use to access your file is relative to the working directory of Tomcat’s process. That is usually $CATALINA_BASE, but can be anything (especially under an IDE).

You should give the path in a more stable way, e.g. by using ServletContext#getRealPath():

JavaScript

Obviously this will fail if your Tomcat does not unpack WARs. However, that is not a common situation.

Advertisement