This question already has an answer here:
这个问题在这里已有答案:
- WildFly - getting resource from WAR 5 answers
WildFly - 从WAR 5获得资源答案
@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:
file.getAbsolutePath()方法返回:
C:\Program Files (x86)\wildfly-10.1.0\bin\standalone\deployments\domaci8.war\login.html
And the login.html file is located here:
login.html文件位于:
C:\Program Files (x86)\wildfly-10.1.0\standalone\deployments\domaci8.war\login.html
1 个解决方案
#1
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.
文件文件=新文件(“standalone / deployments / domaci8.war / login.html”);只是创建一个File对象,该文件的路径是相对于启动JVM进程的文件夹。
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
由于您使用standalone.bat从C:\ Program Files(x86)\ wildfly-10.1.0 \ bin启动了WildFly服务器,这就是file.getAbsolutePath()返回C:\ Program Files(x86)\ wildfly-的原因10.1.0 \ BIN \独立\部署\ domaci8.war \的login.html
If the login.html
is in the same application as the rest service check https://*.com/a/1768290/916225 this answer.
如果login.html与其他服务在同一个应用程序中,请检查https://*.com/a/1768290/916225此答案。
#1
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.
文件文件=新文件(“standalone / deployments / domaci8.war / login.html”);只是创建一个File对象,该文件的路径是相对于启动JVM进程的文件夹。
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
由于您使用standalone.bat从C:\ Program Files(x86)\ wildfly-10.1.0 \ bin启动了WildFly服务器,这就是file.getAbsolutePath()返回C:\ Program Files(x86)\ wildfly-的原因10.1.0 \ BIN \独立\部署\ domaci8.war \的login.html
If the login.html
is in the same application as the rest service check https://*.com/a/1768290/916225 this answer.
如果login.html与其他服务在同一个应用程序中,请检查https://*.com/a/1768290/916225此答案。