简体   繁体   中英

How to get full base path of spring application running on CentOS Wildfly server?

I need to get the full path of my deployed spring application using Java. I tried following to get the path

getClass().getProtectionDomain().getCodeSource().getLocation().getPath()

which returned following:

  • On Wildfly running on CentOS :

"/content/MyProject.war/WEB-INF/classes"

(partial path)

  • On Wildfly running on Win7 :

"/C:/wildfly-8.2.0.Final/standalone/deployments/MyProject.war/WEB-INF/classes"

(returning full path)

Above worked on my Windows machine but not working on Wildfly running on CentOS .

There is no such concept as the full path of a deployed web application - at least not in the Java EE specs, as far as I know.

You seem to assume tacitly that a deployed web application must be located somewhere in a file system and that there is an absolute path of that location.

But this is not necessarily the case, and if it happens to be the case, it's an implementation detail of the app server which your application should not rely on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM