java 在 AWS Beanstalk 中运行 WAR 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38244046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run WAR file in AWS Beanstalk
提问by user3235881
I created a Web Server with java and jersey. I also use MAVEN. I am able to run the project from the command line with this command
我用 java 和 jersey 创建了一个 Web 服务器。我也用MAVEN。我可以使用此命令从命令行运行项目
mvn clean verify org.codehaus.cargo:cargo-maven2-plugin:run
My problem is that I want to deploy the project in an Amazon aws Elastic Beanstalk as a java application. I have to upload the code there and amazon will execute it with this command
我的问题是我想将该项目作为 Java 应用程序部署在 Amazon aws Elastic Beanstalk 中。我必须在那里上传代码,亚马逊将使用此命令执行它
java -jar mywar.war
If I try to run my project locally with this command, I get this error
如果我尝试使用此命令在本地运行我的项目,则会收到此错误
no main manifest attribute, in project.war
So I think that's why the project is not running properly in the Beanstalk. Is it possible to run my project with this java command or I must use the mvn command?
所以我认为这就是该项目在 Beanstalk 中无法正常运行的原因。是否可以使用此 java 命令运行我的项目,或者我必须使用 mvn 命令?
回答by Alexandar Petrov
This is because your maven is using cargo plugin. If you want to run it from the command line like a regular java application you need to start the Jetty or the Tomcat or the whatever you are using in embedded mode. Here is a link describing how to start Jetty from the application.
这是因为您的 Maven 正在使用货物插件。如果您想像常规 Java 应用程序一样从命令行运行它,您需要启动 Jetty 或 Tomcat 或您在嵌入式模式下使用的任何东西。这是一个描述如何从应用程序启动 Jetty 的链接。
http://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html
http://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html
回答by Juned Ahsan
Try to open the manifest file in your generated war file, most likely it is missing the Main-Classinformation. A sample of a MANIFEST file containing that is like:
尝试打开生成的 war 文件中的清单文件,很可能它缺少 Main-Class 信息。包含该文件的 MANIFEST 文件示例如下:
Manifest-Version: 1.0
Main-Class: org.xxx.xxx.
You can try to add the Main file information in the maven plugin config under your pom file. Something like this:
你可以尝试在你的pom文件下的maven插件配置中添加Main文件信息。像这样的东西:
<plugin>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
...
</plugin>