How can I compile my web application and tomcat with maven?

I would like to distribute my application packaged as a WAR embedded in Apache Tomcat. That is, I want to distribute Tomcat along with my application.

How can I make such distribution packaging with Maven?

I saw the Maven Cargo Plugin , but it seems to focus on deploying applications in containers locally. Perhaps an extra step over the Cargo plugin is what I need. cargo:packageIt seems interesting, but there is no documentation.

+5
source share
2 answers

By developing a Tomasz comment, you can do the following to achieve this.

  • tomcat .

    mvn install: install-file -DgroupId = org.apache -DartifactId = tomcat -Dversion = 7.0.10 -Dpackaging = zip -Dfile =/path/to/file

  • unpack maven dependency plugin, tomcat

  • maven assembly plugin, webapps zip

pom.xml .

+8

-, Heroku ( , heroku)

( , )

Tomcat API Tomcat, ,

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>${tomcat.version}</version>
</dependency>

, ,

package launch;

import java.io.File;
import org.apache.catalina.startup.Tomcat;

public class Main {

    public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8080);

        tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
        System.out.println("configuring app with basedir: " + 
            new File("./" + webappDirLocation).getAbsolutePath());

        tomcat.start();
        tomcat.getServer().await();
    }
}
+4

All Articles