1.新建lib目录 如图:
2.pom文件加入本地依赖(坐标随便写,注意scope)
<dependency>
<groupId>zmxy</groupId>
<artifactId>sdk-java-source</artifactId>
<version>20180208162128</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/zmxy-sdk-java-20180208162128-source.jar</systemPath>
</dependency>
3.如果是打成war
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.Date;
@EnableCaching
@EnableScheduling
@EnableAspectJAutoProxy
@EnableTransactionManagement
@ServletComponentScan //扫描自定义filter和servlet、listener之类的
@MapperScan(basePackages = "ccm.mapper")
@SpringBootApplication
public class DatebookApplication extends SpringBootServletInitializer implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(DatebookApplication.class, args);
}
/**
* 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
this.setRegisterErrorPageFilter(false);
return application.sources(DatebookApplication.class);
}
// springboot运行后此方法首先被调用
// 实现CommandLineRunner抽象类中的run方法
@Override
public void run(String... args) throws Exception {
System.out.println("Report time for you: " + new Date().toString() + " ---> darling~ yours springboot2.0 project has been successfully started!nice day,right?");
}
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--本机运行把scope注释掉,打包时scope要带着-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
4.最后就是build
<build>
<finalName>wongh</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/resources/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
5.运行
- 如果是打成jar包 比较简单
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.jar</include>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>fangrong.com.cn.Startup</mainClass>
<fork>true</fork>
<addResources>true</addResources>
<includeSystemScope>true</includeSystemScope> 主要就是这一行
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>