I have a special utility built using spring boot with an embedded tomcat packaged into an executable jar. I am trying to include some js (or maybe json) files in the same directory as the jar file and insert them into the thymeleaf template. For example:
<script type="text/javascript" src="somepath/myfile.js"></script>
Here is what I have achieved so far: In the controller:
String userDirectory = System.getProperty("user.dir");
model.addAttribute("userDir", "file://"+userDirectory+"/");
In the template:
<script type="text/javascript" th:src="${userDir + 'myfile.js'}"></script>
Currently, I can see the code inside myfile.js via Firebug's HTML view, but it does not show up in the scripts tab, and the script is not executed (any variables defined in this file are undefined).
How can I make this work?
I am aware that I could create a json file and process it through Java, but if there is a simpler and more convenient solution available, I would prefer that. Additionally, this way I can use custom javascript instead of just json.
I understand that this approach may be risky in many scenarios, but in this particular case, security is not a concern as the application does not need to be safe from any potential injections via these files.