How to create War to deploy on Tomcat with Spring-Boot?

Asked

Viewed 1,332 times

0

I am creating a project in Spring-Boot and I want to create the.War file to deploy to Tomcat and I am unable to do so. I am following this example but I have not yet had success War is not being generated.

How to do this ?

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>        
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.iguana</groupId>
    <artifactId>CooperativaWS</artifactId>
    <version>0.0.1</version>
    <packaging>war</packaging>
    <name>CooperativaWS</name>
    <description>Cooperativa Web Service</description>


    <properties>        
        <java.version>1.8</java.version>
        <start-class>com.iguana.CooperativaWsApplication</start-class>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency><!-- basic authentication -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- md5 -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>          
        </dependency>

        <!-- Tomcat -->
        <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
           <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>    
                    <mainClass>com.iguana.CooperativaWsApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Springbootapplication

@SpringBootApplication
public class CooperativaWsApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(CooperativaWsApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(CooperativaWsApplication.class);
    }

}

1 answer

1


Are you running the command to generate the build? To do this if you are using spring tools or eclipse you must right-click the project choose "Run as" -> "Maven build." and put in "Goals": clean package and run. If you have Maven installed and want to build outside of spring tools or eclipse navigate through the terminal to your project directory then type: mvn clean package. According to the example you did everything correctly. You can also follow this other example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.