在配置文件中undertow.resourcePath的配置如下
undertow.resourcePath = classpath:bill-biaobei-tts-server
在部署时会部署到不同的目录下,如果在程序中获取真实的undertow.resourcePath路径
编写controller
import java.net.URL; import java.util.HashMap; import java.util.Map; import com.jfinal.core.Controller; import com.jfinal.kit.PathKit; public class PathController extends Controller { public void index() { URL resource = this.getClass().getClassLoader().getResource(""); Map<String, String> map = new HashMap<>(); map.put("rootClassPath", PathKit.getRootClassPath()); map.put("webRootPath", PathKit.getWebRootPath()); map.put("classLoader", resource.getFile()); renderJson(map); } }
windows返回
{ "rootClassPath": "D:\\dev_workspace\\java\\hg_project\\bill-biaobei-tts-server\\target\\classes", "webRootPath": "D:\\dev_workspace\\java\\hg_project\\bill-biaobei-tts-server", "classLoader": "/D:/dev_workspace/java/hg_project/bill-biaobei-tts-server/target/classes/" }
linux使用systemctl启动返回
{ "rootClassPath":"/opt/jfinal/bill-biaobei-tts-server-1.0/config", "webRootPath":"/opt/jfinal/bill-biaobei-tts-server-1.0/webapp", "classLoader":"/opt/jfinal/bill-biaobei-tts-server-1.0/config }
如果进行拼接,都获取不到undertow.resourcePath的真实路径
打包后真实的undertow.resourcePath的真实路径是/opt/jfinal/bill-biaobei-tts-server-1.0/bill-biaobei-tts-server