简体   繁体   English

无法使JAR / WAR可执行文件与嵌入式Tomcat 7一起使用

[英]Cannot make JAR/WAR executable work with embedded Tomcat 7

I have a maven project using the tomcat7-maven-plugin . 我有一个使用tomcat7-maven-plugin的Maven项目。 I am trying to package the project into a jar (or war) so it can be run without using maven ( mvn tomcat7:run ). 我试图将项目打包到一个jar(或war)中,以便可以在不使用maven的情况下运行它( mvn tomcat7:run )。 My attempts so far have not resulted in displaying the webpage correctly. 到目前为止,我的尝试尚未导致正确显示网页。

I have followed the steps in https://www.baeldung.com/executable-jar-with-maven (2.6: Web Application with Executable Tomcat). 我已按照https://www.baeldung.com/executable-jar-with-maven(2.6 :带有可执行Tomcat的Web应用程序)中的步骤进行操作。 Additionally, the video tutorial on https://searchapparchitecture.techtarget.com/video/Create-a-Java-executable-JAR-with-the-Tomcat-plug-in-for-Maven was followed. 此外,还遵循了https://searchapparchitecture.techtarget.com/video/Create-a-Java-executable-JAR-with-the-Tomcat-plug-in-for-Maven上的视频教程。 Several variants of these have been tried, altering the pom.xml parameters. 已经尝试了其中的几种变体,更改了pom.xml参数。 A sample of the pom.xml is here . 这里是pom.xml的示例。

Each time, the archive is built using the command mvn clean install tomcat7:exec-war-only and subsequently a .jar or .war archive is created in the target directory. 每次,都使用命令mvn clean install tomcat7:exec-war-only构建档案,然后在目标目录中创建.jar或.war档案。

After creation, the achieve is run by java -jar Application.jar . 创建后,实现由java -jar Application.jar运行。 The following output is observed: 观察到以下输出:

INFO: Initializing ProtocolHandler ["http-bio-8080"]
Aug 29, 2019 9:58:58 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Aug 29, 2019 9:58:58 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Aug 29, 2019 9:58:58 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]

When navigating to any address, such as http://localhost:8080/Application/home I receive a 404 error page (not served by Tomcat, but Chrome's error page). 导航到任何地址(例如http:// localhost:8080 / Application / home)时,我会收到404错误页面(不是Tomcat提供,而是Chrome的错误页面)。 When running the same application through mvn tomcat7:run the page would load as expected. 通过mvn tomcat7:run运行相同的应用程序时,页面将按预期加载。

Can anyone advise on this please? 任何人都可以对此提出建议吗?

Depending on the packaging ( .jar or .war ), your web page resources (html/css/js files) have to be on different location. 根据包装( .jar.war ),您的网页资源(html / css / js文件)必须位于不同的位置。 And I guess your URI call an index.html page? 而且我猜您的URI称为index.html页面?

  • For .jar packaging put it in src/main/resources folder 对于.jar打包,请将其放在src/main/resources文件夹中
  • For .war packaging put it in src/main/webapp folder 对于.war包装,请将其放在src/main/webapp文件夹中

In your case, your URL is not reachable and I suspect your web resources are not in the good folder. 就您而言,您的URL无法访问,我怀疑您的Web资源不在好文件夹中。

This link can help you understand more clearly 链接可以帮助您更清楚地了解

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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