Expand my Community achievements bar.

How to read an external js file in java class.


Level 2

I am trying to generate hash value for a javascript file in my java class. Im not able to pass the path of the javascript file to my Java method. Could you please suggest where to store js files and how to access them from my java model?


For example, could someone suggest what path to give for my js script here - 


public String Hashes() {
List<String> jsFiles = new ArrayList<>();



5 Replies


Level 7

Keep the js file in your project DAM location (example: /content/dam/abc/jsFiles

Read the js file from java logic. 

Query: Are you going to modify the js file content from java logic?

no, I just need to read the js file and generate hash 512 for the same to avoid using unsafe-inline in CSP. So this should work?

public String Hashes() {
List<StringjsFiles = new ArrayList<>();


Community Advisor

hi @Silvia_Joyce_Balraj  you can save the file in DAM location or etc/clientlibs location. But can you explain the exact business requirement for this. Never came across such ask till now 


Community Advisor

Hi @Silvia_Joyce_Balraj 

Were the user suggestions helpful? Let us know if more details are needed or mark the answer as correct. If you found a solution independently, please share it with the community.

Arun Patidar