1
@Path("/other")
public class Testclass {
   @GET
   @Path("/filepath")
   @Produces("text/html")
   public FileInputStream login() {
       File file = new File("standalone/deployments/domaci8.war/login.html");
       try {
           return new FileInputStream(file.getAbsolutePath());
       } catch (FileNotFoundException e) {
           e.printStackTrace();
           return null;
       }
   }
}

file.getAbsolutePath() method returns this:

C:\Program Files (x86)\wildfly-10.1.0\bin\standalone\deployments\domaci8.war\login.html

And the login.html file is located here:

C:\Program Files (x86)\wildfly-10.1.0\standalone\deployments\domaci8.war\login.html
milos
  • 77
  • 3
  • 10

1 Answers1

2

File file = new File("standalone/deployments/domaci8.war/login.html"); is just creating a File object and the path to the file is relative to the folder where the JVM process is started.

Since you have started the WildFly server from C:\Program Files (x86)\wildfly-10.1.0\bin using standalone.bat that's the reason the file.getAbsolutePath() is returning C:\Program Files (x86)\wildfly-10.1.0\bin\standalone\deployments\domaci8.war\login.html

If the login.html is in the same application as the rest service check https://stackoverflow.com/a/1768290/916225 this answer.

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • `file.getParent()` will return `null` in my problem, so the only solution I found is to create a file `new File("")` then create `String path = file.getAbsolouthPath()`, trim the string with `path = path.substring(0, path.indexOf("\\bin"))`, then you need to concatenate `path += "\\standalone\\deployments\\domaci8.war\\login.html\\"` and it works that way. Thanks for assist. – milos May 21 '18 at 12:12
  • This thread finally solved my problem https://stackoverflow.com/questions/23845031/wildfly-getting-resource-from-war – milos May 21 '18 at 15:02