如何在具有用于 WebComponents 的 StaticFiles 文件夹的 Heroku 中使用 Java Spark 部署 Web 应用程序
How to Deploy WebApplication Using JavaSpark in Heroku Which Has StaticFilesFolder for WebComponents
我想在 Heroku 上部署一个 Web 应用程序,必须使用 WebSocketServer.ja
中的 staticfilesfolder 提供服务
port(getHerokuAssignedPort());
webSocketIdleTimeoutMillis(1000000000);
staticFileLocation("/public");
webSocket("/em/", WebSocketHandler.class);
init();
和websocketClient.js
var webSocket = new WebSocket("ws://" + location.hostname + ":" + location.port + "/em/");
但我无法为来自 /public folder.It 的 *.html、*.css、*.js 文件提供服务,但在我的本地服务器上运行良好系统无法在 heroku 上运行 site.It 显示应用程序错误。
public class Bootstrap {
private static final int DEFAULT_PORT = 4567;
public static void main(String[] args) throws URISyntaxException {
port(getHerokuAssignedPort());
externalStaticFileLocation(getPublicFolderPath());
}
private static int getHerokuAssignedPort() {
ProcessBuilder processBuilder = new ProcessBuilder();
if (processBuilder.environment().get("PORT") != null) {
return Integer.parseInt(processBuilder.environment().get("PORT"));
}
return DEFAULT_PORT;
}
private static String getPublicFolderPath() throws URISyntaxException{
CodeSource codeSource = Bootstrap.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
return jarDir + File.separator + "public";
}}
/public directory should be in the same folder as build jar file.
我想在 Heroku 上部署一个 Web 应用程序,必须使用 WebSocketServer.ja
中的 staticfilesfolder 提供服务 port(getHerokuAssignedPort());
webSocketIdleTimeoutMillis(1000000000);
staticFileLocation("/public");
webSocket("/em/", WebSocketHandler.class);
init();
和websocketClient.js
var webSocket = new WebSocket("ws://" + location.hostname + ":" + location.port + "/em/");
但我无法为来自 /public folder.It 的 *.html、*.css、*.js 文件提供服务,但在我的本地服务器上运行良好系统无法在 heroku 上运行 site.It 显示应用程序错误。
public class Bootstrap {
private static final int DEFAULT_PORT = 4567;
public static void main(String[] args) throws URISyntaxException {
port(getHerokuAssignedPort());
externalStaticFileLocation(getPublicFolderPath());
}
private static int getHerokuAssignedPort() {
ProcessBuilder processBuilder = new ProcessBuilder();
if (processBuilder.environment().get("PORT") != null) {
return Integer.parseInt(processBuilder.environment().get("PORT"));
}
return DEFAULT_PORT;
}
private static String getPublicFolderPath() throws URISyntaxException{
CodeSource codeSource = Bootstrap.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
return jarDir + File.separator + "public";
}}
/public directory should be in the same folder as build jar file.