zoukankan      html  css  js  c++  java
  • springboot静态资源配置_打包发布

    一、静态资源配置

    a、配置application.yml

    spring:
      resources:
        static-locations: classpath:/static/

    二、打包war发布

    a、需要打成war包

    <packaging>war</packaging>
    
    <!-- maven项目packaging为war类型时,必须要加这个插件 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

    b、配置pom.xml

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

    c、启动类

    @SpringBootApplication(scanBasePackages = { "com.wuxi" })
    public class MySpringApplication extends SpringBootServletInitializer {
        public static void main(String[] args) throws Exception {
            SpringApplication.run(MySpringApplication.class, args);
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(MySpringApplication.class);
        }
    }

    d、执行maven命令

    clean package:在target目录下生成war包

    三、打jar包发布

    a、配置pom.xml(运行mvn package命令即可打包)

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    b、运行命令

    java -jar 【打的jar包名】

    四、微服务打包构建

    父模块

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <!--springboot 打包插件 ,不然报错 Unable to find main class
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            -->
        </plugins>
        <resources>
            <!--
                src/main/java目录下的mapper.xml文件,需此配置才能打进包里
            -->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

    子模块(没有启动器的模块不能加)

    <!-- 打包插件 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  • 相关阅读:
    Log4NET初接触
    wwwww
    关于ASP.NET 的进程帐户对 IIS 元数据库读访问权问题
    CentOS8 .NET Core项目部署
    CentOS7.6中安装Apache及Apache常见操作和配置说明
    .net core 命令行下启动指定端口
    Centos7安装mongodb
    centos8+oracle19开机自启动
    计算机网络常用端口
    Centos7安装mongodb
  • 原文地址:https://www.cnblogs.com/linding/p/12591245.html
Copyright © 2011-2022 走看看