Question

I am making a Java application that uses, Spring, Maven and the AWS-SDK-Java. In order to the AWS SDK to work I have to place the AWSCredentials.properties file inside the "MyProject/src/main/resources" folder.

So far so so good. Then I have to create a .war file. To do that I use mvn install command and voilá.

Now inside the .war created, the file I want to access is in the "/WEB-INF/classes/" folder and I need to read it.

How can I access this file inside the war so I can read its content? I have experimented with ServeltContext but so far nothing I try works!

Was it helpful?

Solution 2

I found a way to do it. I can access the file by using:

InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/resources/email/file.txt");

As explained in this discusison: Reading a text file in war archive

OTHER TIPS

It is generally not a good practice to keep credential in code package (war). Instead I would suggest you use IAM Roles.

This will make it easy for you to move your code from one AWS account to another (say dev environment to production). Since the code will be submitted to a version control system which will be accessed by many, it is also good from a security point of view to use IAM roles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top