0

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!

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
  • A quick way to see what's in a war file (on a *nix OS) is to use tar + grep. E.g, this command will show you all the properties files in your war: tar tvf | grep properties – Alex Mar 02 '14 at 18:46
  • 1
    A `.war` is a webapp archive. Compiled sources usually go to `/WEB-INF/classes`, so you should search the file in `/WEB-INF/classes/main/resources` – SJuan76 Mar 02 '14 at 18:50
  • Alrigth, now I know where the file is! How to I tell me webapp to read it? I will update this question now ! – Flame_Phoenix Mar 02 '14 at 18:54

2 Answers2

2

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.

Sony Kadavan
  • 3,982
  • 2
  • 19
  • 26
0

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

Community
  • 1
  • 1
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266