0

This is working correctly locally, but not when hosting on AWS. I've been attempting to debug this for a week and can't seem to crack it.

Here is the code block that I believe is causing my issue. In short, I'm attempting to find the "resources" directory inside my project that is holding some .jmx files (JMeter tests), and put them into a list. The "slash" variable is holding System.getProperty("file.separator").

Stream<Path> walk = Files.walk(Paths.get(System.getProperty("user.dir") + slash + "src" + slash + "main" + slash + "resources"), 1)) {
                result = walk.map(x -> x.toString())
                        .filter(f -> f.endsWith(".jmx") )
                        .collect(Collectors.toList());

When running locally, the directory is: C:\Users\user.name\repos\my-project\src\main\resources

When running on AWS it looks like the directory is: /usr/share/apache-tomcat-8.5.30/src/main/resources

Here is the error I'm getting after deploying to an AWS instance:

java.nio.file.NoSuchFileException: /usr/share/apache-tomcat-8.5.30/src/main/resources

Am I missing something with how System.getProperty("user.dir") would work when hosted on AWS? My thought is that looking for a specific directory instead of just getting "user.dir" is causing some issue, but I'm not sure.

So far I've tried:

  • Making sure there aren't any access issues with AWS
  • Adding and removing the trailing slash at the end of the directory path
  • Removing the + slash + "src" + slash + "main" + slash + "resources" so it's just grabbing "user.dir", which seems to work, but I need to be able to get more specific with the folder location.
Cory Bergquist
  • 445
  • 4
  • 12
  • The problem is that you're trying to read a source directory, and that source directory doesn't exist when you've deployed the program as a WAR. Normally this is easy to work-around: you know the name of the file that you want to load, and can use `Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)`. However, you want to get a listing of files, and there's no portable way to do that. I don't have the time to write up a detailed explanation of how you can do this, so I recommend Googling for "get list of resources from classloader". – Parsifal Apr 13 '21 at 13:07
  • @Parsifal I'll look into that thanks! – Cory Bergquist Apr 13 '21 at 15:24
  • Linking this for anyone who might stumble on my question. I solved my issue and explained it in the answer here: https://stackoverflow.com/questions/67083073/trouble-using-pathmatchingresourcepatternresolver-to-get-src-main-resources-in-w – Cory Bergquist Jun 07 '21 at 23:37

0 Answers0