英文:
JAR file runs on Windows but not on Linux
问题
我已在Maven上创建了一个JAR文件。这个应用程序包含了Spring Boot和Vaadin。我可以在Windows上运行它。但当我尝试在Linux上运行时,它显示Tomcat无法启动。
我在想这是否与OpenJDK有关,因为这是我现在看到的唯一区别。在Windows上,我使用Oracle JDK 8。
我尝试在AWS、Docker、Ubuntu上运行。结果相同。
Windows 10 - 正常。
org.springframework.context.ApplicationContextException: 无法启动Web服务器;嵌套异常为 org.springframework.boot.web.server.WebServerException: 无法启动嵌入式Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at no.safe4.dynamodbcsvui.Application.main(Application.java:14) [classes!/:1.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111-internal]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111-internal]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111-internal]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111-internal]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [dynamodb-csv-ui-1.0.jar:1.0]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [dynamodb-csv-ui-1.0.jar:1.0]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [dynamodb-csv-ui-1.0.jar:1.0]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [dynamodb-csv-ui-1.0.jar:1.0]
Caused by: org.springframework.boot.web.server.WebServerException: 无法启动嵌入式Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:88) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:438) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:191) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
... 16 common frames omitted
Caused by: java.lang.IllegalStateException: StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[] 无法启动
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.rethrowDeferredStartupExceptions(TomcatWebServer.java:171) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:110) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
英文:
I have created a JAR file on Maven. This application contains Spring Boot and Vaadin. I can run it on Windows. When I try to run on Linux, it says the Tomcat can't start.
I was wondering if it's a problem with OpenJDK because this is the only difference I see now. On Windows I use Oracle JDK 8.
I tried to run on AWS, Docker, Ubuntu. Same result.
Windows 10 - OK.
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.2.0.RELEASE.jar!/:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at no.safe4.dynamodbcsvui.Application.main(Application.java:14) [classes!/:1.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111-internal]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111-internal]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111-internal]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111-internal]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [dynamodb-csv-ui-1.0.jar:1.0]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [dynamodb-csv-ui-1.0.jar:1.0]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [dynamodb-csv-ui-1.0.jar:1.0]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [dynamodb-csv-ui-1.0.jar:1.0]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:88) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:438) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:191) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
... 16 common frames omitted
Caused by: java.lang.IllegalStateException: StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[] failed to start
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.rethrowDeferredStartupExceptions(TomcatWebServer.java:171) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:110) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]org.springframework.context.ApplicationContextException:: command not found
答案1
得分: 1
我找到了问题/解决方案:
-
在 application.properties 中添加了 debug=true
-
运行后我找到了它:
造成原因:java.lang.IllegalStateException: 在开发模式下运行项目,无法访问文件夹...
改为在生产模式下构建项目,参见 https://vaadin.com/docs/v14/flow/production/tutorial-production-mode-basic.html -
在 Vaadin 的 GitHub 上,有一种在生产中创建 JAR 文件的方法:
mvn clean package -Pproduction
这解决了问题,应用程序正在运行。
英文:
I found the problem/solution:
-
Added debug=true to application.properties
-
After run I found it:
Caused by: java.lang.IllegalStateException: Running project in development mode with no access to folder...
Build project in production mode instead, see https://vaadin.com/docs/v14/flow/production/tutorial-production-mode-basic.html -
On Vaadin GitHub, there is a way to create the JAR file in production:
mvn clean package -Pproduction
That solved the problem and the application is running.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论