简体   繁体   English

部署一个jar中包含tomcat的Web应用程序

[英]Deploy a web application with tomcat included in one jar

I need to create a simple jar containing my Tomcat8 setup and my web application war. 我需要创建一个包含我的Tomcat8设置和Web应用程序战争的简单jar。

Why? 为什么? I want to create a portable web application, meaning that you can host it anywhere, on a linux, windows, mac, whatever. 我想创建一个可移植的Web应用程序,这意味着您可以在Linux,Windows,Mac等任何地方托管它。 The only thing needed is the jar file, and all your data is saved in a "data" folder created in the folder containing the current jar file. 唯一需要的是jar文件,所有数据都保存在包含当前jar文件的文件夹中创建的“数据”文件夹中。

The goal is to create a jar file you that just have to start to start tomcat and it's done, your web application is ready and listening. 目标是创建一个只需要开始启动tomcat的jar文件,它已完成,您的Web应用程序已准备就绪且正在侦听。

I don't know if it is even possible, but I found nothing using google. 我什至不知道是否有可能,但使用Google我一无所获。

PS: I will use VAADIN7(for the web app), Jersey JAX-RS(for a rest api) and Neo4j (for the datas) PS:我将使用VAADIN7(用于Web应用程序),Jersey JAX-RS(用于其他API)和Neo4j(用于数据)

As described in this blog entry: Standalone web application with executable Tomcat 如本博客文章所述: 具有可执行Tomcat的独立Web应用程序

You can use a tomcat7:exec-war maven goal to create self executable jar with all tomcat classes. 您可以使用tomcat7:exec-war maven目标创建包含所有tomcat类的自可执行jar。

So you will be able to use only: java -jar createjar.jar to run your webapp without need to install an Apache Tomcat instance. 因此,您将只能使用: java -jar createjar.jar来运行您的java -jar createjar.jar应用程序,而无需安装Apache Tomcat实例。

You have to extend your pom.xml with this plugin entry: 您必须使用以下插件条目扩展pom.xml

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <executions>
        <execution>
            <id>tomcat-run</id>
            <goals>
                <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <path>/application</path>
                <enableNaming>false</enableNaming>
                <finalName>application.jar</finalName>
                <charset>utf-8</charset>
            </configuration>
        </execution>
    </executions>
</plugin>

Build your application: mvn package 构建您的应用程序: mvn package

And run Tomcat along with your embedded application: $ java -jar application.jar 并与嵌入式应用程序一起运行Tomcat: $ java -jar application.jar

Alternatively, check this Heroku tutorial describing the process of creating a web app with embedded Tomcat: Create a Java Web Application Using Embedded Tomcat . 或者,查看此Heroku教程,该教程描述了使用嵌入式Tomcat 创建Web应用程序的过程:使用嵌入式Tomcat创建Java Web应用程序

I was able to run the project within 10 minutes just followed the instructions on http://projects.spring.io/spring-boot/#quick-start 我能够按照http://projects.spring.io/spring-boot/#quick-start上的说明在10分钟内运行该项目

Spring boot is amazing in the sense that it packages all the necessary things we need and helps reduce development cost on infrastructure etc. Helps devs focus on delivering the actual business value. Spring Boot可以打包我们需要的所有必要内容,并有助于降低基础架构等的开发成本,因此它是惊人的。帮助开发人员专注于交付实际的业务价值。

Micro services ( as i have mentioned in multiple threads) is achiveable and made easy with this spring boot approach. 通过这种春季启动方法,微服务(如我在多个线程中提到的)是可以实现的,并且变得容易。

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

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