Use Maven for deploy SpringBoot application to remote tomcat 7/8
To pom.xml add:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://MyTomcatServer:8080/manager/text</url>
<server>TomcatServer</server>
<path>/restforjs</path>
</configuration>
</plugin>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://MyTomcatServer:8080/manager/text</url>
<server>TomcatServer</server>
<path>/restforjs</path>
</configuration>
</plugin>
To
<main.basedir>${basedir}/../..</main.basedir>
Set "packaging" to war in section <properties>
<packaging>war</packaging>
Set your login/pasword in $USER_HOME/.m2/settings.xml . Example:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>TomcatServer</id>
<username>tomcatadmin</username>
<password>MyCoolPassword</password>
</server>
</servers>
</settings>
Main class must extends SpringBootServletInitializer and overrides configure such as in example:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class MyCoolApplicationextends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyCoolApplication.class);
}
public static void main(String[] args) {
MyCoolApplication.run(MyCoolApplication.class, args);
}
}
After this run to deploy:
mvn tomcat7:deploy
Exist instance must had undeployed before that action:
mvn tomcat7:undeploy
You can run one command
mvn tomcat7:undeploy tomcat7:deploy
Comments
Post a Comment