1、pom中配置static的打包路径
<plugins>
<!--**********分离资源文件及依赖包打包配置*************-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
<exclude>static/**</exclude>
<exclude>template/**</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.InfoWebApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>non-exists</groupId>
<artifactId>non-exists</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>classes</classifier>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="dist">target/build</property>
<property name="res">target/build/resources</property>
<property name="dist-tmp">target/build/tmp</property>
<property name="app-name">${project.artifactId}-${project.version}</property>
<property name="real-app-name">${project.artifactId}</property>
<delete dir="${dist}" />
<mkdir dir="${dist}" />
<mkdir dir="${dist-tmp}" />
<mkdir dir="${res}" />
<copy file="target/${app-name}.jar" tofile="${dist-tmp}/${app-name}.jar" />
<unzip src="${dist-tmp}/${app-name}.jar" dest="${dist-tmp}" />
<delete file="${dist-tmp}/${app-name}.jar" />
<!-- <move file="target/${app-name}-classes.jar" tofile="${dist}/${real-app-name}.jar"/> -->
<move file="target/${app-name}-classes.jar" tofile="${dist}/${app-name}.jar"/>
<move todir="${dist}/lib">
<fileset dir="target/lib" />
</move>
<delete dir="${dist-tmp}" />
<copy todir="${res}">
<fileset dir="target/classes">
<include name="**/static/**" />
<include name="**/template/**" />
</fileset>
</copy>
<copy todir="${res}">
<fileset dir="target/classes">
<include name="**/*.properties" />
<include name="**/*.xml" />
<include name="**/*.yml" />
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
2、application.properties配置
spring.mvc.static-path-pattern=/**
3、创建文件夹
在resources下面创建static文件夹,并在static下面放静态文件
网友评论