简体   繁体   中英

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.

Why? I want to create a portable web application, meaning that you can host it anywhere, on a linux, windows, mac, whatever. 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.

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.

I don't know if it is even possible, but I found nothing using google.

PS: I will use VAADIN7(for the web app), Jersey JAX-RS(for a rest api) and Neo4j (for the datas)

As described in this blog entry: Standalone web application with executable Tomcat

You can use a tomcat7:exec-war maven goal to create self executable jar with all tomcat classes.

So you will be able to use only: java -jar createjar.jar to run your webapp without need to install an Apache Tomcat instance.

You have to extend your pom.xml with this plugin entry:

<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

And run Tomcat along with your embedded application: $ 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 .

I was able to run the project within 10 minutes just followed the instructions on http://projects.spring.io/spring-boot/#quick-start

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.

Micro services ( as i have mentioned in multiple threads) is achiveable and made easy with this spring boot approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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